@innovatorved/code-lab 0.3.2 → 0.4.0

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.
Files changed (155) hide show
  1. package/ARCHITECTURE.md +5 -3
  2. package/CHANGELOG.md +20 -0
  3. package/README.md +70 -168
  4. package/dist/apps/web/src/index.d.ts +34 -0
  5. package/dist/code-lab-sql.css +482 -0
  6. package/dist/code-lab-sql.d.ts +179 -0
  7. package/dist/code-lab-sql.esm.js +542 -0
  8. package/dist/code-lab-sql.umd.js +531 -0
  9. package/dist/code-lab.css +246 -0
  10. package/dist/code-lab.d.ts +110 -15
  11. package/dist/code-lab.esm.js +34265 -18104
  12. package/dist/code-lab.js +33186 -17053
  13. package/dist/code-lab.umd.js +65502 -0
  14. package/dist/extensions/cpp.esm.js +19478 -3760
  15. package/dist/extensions/cpp.js +19475 -3757
  16. package/dist/extensions/guided-lab.esm.js +19401 -3725
  17. package/dist/extensions/guided-lab.js +19400 -3724
  18. package/dist/extensions/python.d.ts +1 -0
  19. package/dist/extensions/python.esm.js +19576 -3766
  20. package/dist/extensions/python.js +19576 -3766
  21. package/dist/extensions/umbrella.d.ts +5 -0
  22. package/dist/index.d.ts +1 -1
  23. package/dist/modular-kernel.d.ts +11 -0
  24. package/dist/packages/commands/src/index.d.ts +96 -0
  25. package/dist/packages/core/src/di.d.ts +36 -0
  26. package/dist/packages/core/src/disposable.d.ts +27 -0
  27. package/dist/packages/core/src/errors.d.ts +69 -0
  28. package/dist/packages/core/src/events.d.ts +38 -0
  29. package/dist/packages/core/src/index.d.ts +6 -0
  30. package/dist/packages/core/src/path.d.ts +14 -0
  31. package/dist/packages/core/src/registry.d.ts +23 -0
  32. package/dist/packages/editor/src/index.d.ts +118 -0
  33. package/dist/packages/fs/src/backends.d.ts +37 -0
  34. package/dist/packages/fs/src/index.d.ts +3 -0
  35. package/dist/packages/fs/src/types.d.ts +40 -0
  36. package/dist/packages/fs/src/vfs-service.d.ts +33 -0
  37. package/dist/packages/preview/src/index.d.ts +34 -0
  38. package/dist/packages/runtime/src/index.d.ts +47 -0
  39. package/dist/packages/settings/src/builtin-schemas.d.ts +15 -0
  40. package/dist/packages/settings/src/configuration-service.d.ts +100 -0
  41. package/dist/packages/settings/src/index.d.ts +4 -0
  42. package/dist/packages/settings/src/jsonc.d.ts +20 -0
  43. package/dist/packages/settings/src/schema.d.ts +28 -0
  44. package/dist/packages/sql/src/completions.d.ts +8 -0
  45. package/dist/packages/sql/src/diagnostics.d.ts +2 -0
  46. package/dist/packages/sql/src/formatter.d.ts +2 -0
  47. package/dist/packages/sql/src/index.d.ts +7 -0
  48. package/dist/packages/sql/src/sql-editor.d.ts +2 -0
  49. package/dist/packages/sql/src/styles.d.ts +2 -0
  50. package/dist/packages/sql/src/tokenizer.d.ts +13 -0
  51. package/dist/packages/sql/src/types.d.ts +130 -0
  52. package/dist/packages/terminal/src/index.d.ts +54 -0
  53. package/dist/packages/ui/src/index.d.ts +4 -0
  54. package/dist/packages/ui/src/observability.d.ts +22 -0
  55. package/dist/packages/ui/src/plugin-registry.d.ts +89 -0
  56. package/dist/packages/ui/src/settings-dialog.d.ts +25 -0
  57. package/dist/packages/ui/src/themes.d.ts +35 -0
  58. package/dist/preview-sw.js +53 -12
  59. package/dist/runtime.d.ts +3 -3
  60. package/dist/runtime.esm.js +467 -44
  61. package/dist/runtime.js +465 -44
  62. package/dist/schemas.d.ts +234 -814
  63. package/dist/schemas.esm.js +19401 -3725
  64. package/dist/schemas.js +19404 -3728
  65. package/dist/shell.d.ts +1 -1
  66. package/dist/shell.esm.js +364 -39
  67. package/dist/shell.js +364 -39
  68. package/dist/terminal.esm.js +62 -3
  69. package/dist/terminal.js +62 -3
  70. package/dist/workbench/diff-editor.d.ts +1 -0
  71. package/package.json +37 -8
  72. package/packages/commands/README.md +7 -0
  73. package/packages/commands/package.json +16 -0
  74. package/packages/commands/src/index.ts +467 -0
  75. package/packages/commands/tsconfig.json +22 -0
  76. package/packages/core/README.md +12 -0
  77. package/packages/core/package.json +13 -0
  78. package/packages/core/src/di.ts +147 -0
  79. package/packages/core/src/disposable.ts +112 -0
  80. package/packages/core/src/errors.ts +205 -0
  81. package/packages/core/src/events.ts +157 -0
  82. package/packages/core/src/index.ts +49 -0
  83. package/packages/core/src/path.ts +118 -0
  84. package/packages/core/src/registry.ts +61 -0
  85. package/packages/core/tsconfig.json +19 -0
  86. package/packages/editor/README.md +9 -0
  87. package/packages/editor/package.json +18 -0
  88. package/packages/editor/src/index.ts +344 -0
  89. package/packages/editor/tsconfig.json +24 -0
  90. package/packages/fs/README.md +7 -0
  91. package/packages/fs/package.json +16 -0
  92. package/packages/fs/src/backends.ts +301 -0
  93. package/packages/fs/src/index.ts +18 -0
  94. package/packages/fs/src/types.ts +44 -0
  95. package/packages/fs/src/vfs-service.ts +257 -0
  96. package/packages/fs/tsconfig.json +22 -0
  97. package/packages/preview/README.md +3 -0
  98. package/packages/preview/package.json +16 -0
  99. package/packages/preview/src/index.ts +125 -0
  100. package/packages/preview/tsconfig.json +22 -0
  101. package/packages/runtime/README.md +3 -0
  102. package/packages/runtime/package.json +17 -0
  103. package/packages/runtime/src/index.ts +134 -0
  104. package/packages/runtime/tsconfig.json +23 -0
  105. package/packages/settings/README.md +7 -0
  106. package/packages/settings/package.json +16 -0
  107. package/packages/settings/src/builtin-schemas.ts +235 -0
  108. package/packages/settings/src/configuration-service.ts +543 -0
  109. package/packages/settings/src/index.ts +37 -0
  110. package/packages/settings/src/jsonc.ts +189 -0
  111. package/packages/settings/src/schema.ts +164 -0
  112. package/packages/settings/tsconfig.json +22 -0
  113. package/packages/sql/README.md +12 -0
  114. package/packages/sql/package.json +13 -0
  115. package/packages/sql/src/completions.ts +359 -0
  116. package/packages/sql/src/diagnostics.ts +200 -0
  117. package/packages/sql/src/formatter.ts +271 -0
  118. package/packages/sql/src/index.ts +54 -0
  119. package/packages/sql/src/sql-editor.ts +802 -0
  120. package/packages/sql/src/styles.ts +501 -0
  121. package/packages/sql/src/tokenizer.ts +457 -0
  122. package/packages/sql/src/types.ts +148 -0
  123. package/packages/sql/tsconfig.json +19 -0
  124. package/packages/terminal/README.md +3 -0
  125. package/packages/terminal/package.json +16 -0
  126. package/packages/terminal/src/index.ts +183 -0
  127. package/packages/terminal/tsconfig.json +22 -0
  128. package/packages/ui/README.md +8 -0
  129. package/packages/ui/package.json +18 -0
  130. package/packages/ui/src/index.ts +36 -0
  131. package/packages/ui/src/observability.ts +175 -0
  132. package/packages/ui/src/plugin-registry.ts +274 -0
  133. package/packages/ui/src/settings-dialog.ts +293 -0
  134. package/packages/ui/src/themes.ts +174 -0
  135. package/packages/ui/tsconfig.json +24 -0
  136. package/src/code-lab.css +246 -0
  137. package/src/extensions/cpp.ts +58 -15
  138. package/src/extensions/python.ts +156 -24
  139. package/src/extensions/umbrella.ts +5 -0
  140. package/src/index.ts +1 -1
  141. package/src/modular-kernel.ts +11 -0
  142. package/src/preview-sw.js +52 -11
  143. package/src/runtime.ts +466 -46
  144. package/src/schemas.ts +62 -62
  145. package/src/shell.ts +363 -39
  146. package/src/terminal.ts +60 -2
  147. package/src/workbench/diff-editor.ts +66 -6
  148. package/src/workbench/icons.ts +5 -2
  149. package/src/workbench.ts +2410 -220
  150. package/dist/runtime/index.d.ts +0 -4
  151. package/dist/shell/coreutils/compilers-cli.d.ts +0 -24
  152. package/dist/shell/index.d.ts +0 -4
  153. package/src/runtime/index.ts +0 -5
  154. package/src/shell/coreutils/compilers-cli.ts +0 -103
  155. package/src/shell/index.ts +0 -5
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.3.2 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.4.0 — Standalone Browser Code IDE & Virtual Runtime
4
4
  * ============================================================
5
5
  * Features:
6
6
  * - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
@@ -86,6 +86,7 @@ var CodeLabLogger = (() => {
86
86
  } catch (err) {
87
87
  sinkError = err;
88
88
  }
89
+ void sinkError;
89
90
  }
90
91
  const consoleObj = typeof console !== "undefined" ? console : null;
91
92
  const fn = consoleObj ? consoleObj[level] : null;
@@ -1237,7 +1238,13 @@ function __initVirtualRuntime(rootScope) {
1237
1238
  });
1238
1239
  }
1239
1240
 
1241
+ let _activeStdin = '';
1242
+
1240
1243
  const fsShim = {
1244
+ _setActiveStdin(text) {
1245
+ _activeStdin = text !== undefined && text !== null ? String(text) : '';
1246
+ },
1247
+
1241
1248
  existsSync(p) {
1242
1249
  try {
1243
1250
  const np = normPath(p);
@@ -1462,6 +1469,11 @@ function __initVirtualRuntime(rootScope) {
1462
1469
  },
1463
1470
 
1464
1471
  readFileSync(p, opts) {
1472
+ if (p === 0 || p === '/dev/stdin') {
1473
+ const stdinBuf = VirtualBuffer.from(String(_activeStdin || ''), 'utf8');
1474
+ const encoding = typeof opts === 'string' ? opts : (opts && opts.encoding);
1475
+ return encoding ? stdinBuf.toString(encoding) : stdinBuf;
1476
+ }
1465
1477
  const np = normPath(p);
1466
1478
  if (dirs.has(np)) throw fsError('EISDIR', 'read', p, 'illegal operation on a directory');
1467
1479
  const inode = files.get(np);
@@ -1821,6 +1833,10 @@ function __initVirtualRuntime(rootScope) {
1821
1833
 
1822
1834
  items.sort((a, b) => a.path.localeCompare(b.path));
1823
1835
  return items;
1836
+ },
1837
+
1838
+ _listOpenFds() {
1839
+ return Array.from(fdTable.keys());
1824
1840
  }
1825
1841
  };
1826
1842
 
@@ -1975,6 +1991,13 @@ function __initVirtualRuntime(rootScope) {
1975
1991
  };
1976
1992
 
1977
1993
  fsShim.promises = fsPromises;
1994
+ fsShim._exportRawState = () => {
1995
+ const clonedFiles = new Map();
1996
+ for (const [k, v] of files.entries()) {
1997
+ clonedFiles.set(k, v.data instanceof Uint8Array ? v.data.slice() : new Uint8Array(v.data || 0));
1998
+ }
1999
+ return { files: clonedFiles, dirs: new Set(dirs) };
2000
+ };
1978
2001
 
1979
2002
  return fsShim;
1980
2003
  }
@@ -4705,13 +4728,17 @@ function __initVirtualRuntime(rootScope) {
4705
4728
  function transpileTS(source, filename = 'module.ts', opts = {}) {
4706
4729
  // `keepEsm` leaves `import`/`export` statements intact so the output can run
4707
4730
  // natively in a browser as an ES module (used by the built-in preview server).
4708
- const keepEsm = Boolean(opts && opts.keepEsm);
4709
- const isTS = /\.(ts|tsx|mts|cts)$/i.test(filename)
4731
+ const keepEsm = Boolean(opts && (opts.keepEsm || opts.expressionOnly));
4732
+ const expressionOnly = Boolean(opts && opts.expressionOnly);
4733
+ const isTS = expressionOnly
4734
+ || /\.(ts|tsx|mts|cts)$/i.test(filename)
4710
4735
  || /^[ \t]*(?:export\s+)?(?:abstract\s+class\s+[A-Za-z_$]|declare\s+(?:const|let|var|function|class|namespace|module|global)\b|interface\s+[A-Za-z_$][A-Za-z0-9_$]*|type\s+[A-Za-z_$][A-Za-z0-9_$]*\s*(?:<[^>]*>)?\s*=|enum\s+[A-Za-z_$][A-Za-z0-9_$]*\s*\{|namespace\s+[A-Za-z_$][A-Za-z0-9_$]*\s*\{)/m.test(source);
4711
- const hasESM = /^\s*(?:import|export)\b/m.test(source)
4736
+ const hasESM = !expressionOnly && (
4737
+ /^\s*(?:import|export)\b/m.test(source)
4712
4738
  || /\bexport\s*\{/.test(source)
4713
4739
  || /\bimport\s*\{/.test(source)
4714
- || /\bexport\s+default\b/.test(source);
4740
+ || /\bexport\s+default\b/.test(source)
4741
+ );
4715
4742
  const hasJsx = detectJsxSyntax(source, filename);
4716
4743
  if (!isTS && !hasESM && !hasJsx) return source;
4717
4744
 
@@ -4719,7 +4746,7 @@ function __initVirtualRuntime(rootScope) {
4719
4746
  if (hasJsx) {
4720
4747
  const { pragma, frag } = readJsxPragma(source);
4721
4748
  const hasReactBinding = /\bimport\s+(?!type\b)(?:\*\s+as\s+React\b|React\b)|(?:\bconst|\blet|\bvar|\bfunction|\bclass)\s+React\b|\bReact\s*=/.test(source);
4722
- const needsReact = pragma === 'React.createElement' && (keepEsm ? !hasReactBinding : !/\bReact\b/.test(source));
4749
+ const needsReact = !expressionOnly && pragma === 'React.createElement' && (keepEsm ? !hasReactBinding : !/\bReact\b/.test(source));
4723
4750
  const transformed = jsxTransform(source, { pragma, frag });
4724
4751
  if (transformed !== source) {
4725
4752
  source = transformed;
@@ -4807,18 +4834,80 @@ function __initVirtualRuntime(rootScope) {
4807
4834
  i = j;
4808
4835
  continue;
4809
4836
  }
4810
- // Template literal
4837
+ // Template literal (recursively transpile TypeScript inside ${...} expressions)
4811
4838
  if (ch === '`') {
4812
4839
  let j = i + 1;
4813
- let depth = 0;
4840
+ let rebuilt = '`';
4814
4841
  while (j < len) {
4815
- if (source[j] === '\\') { j += 2; continue; }
4816
- if (source[j] === '$' && source[j + 1] === '{') { depth++; j += 2; continue; }
4817
- if (source[j] === '}' && depth > 0) { depth--; j++; continue; }
4818
- if (source[j] === '`' && depth === 0) { j++; break; }
4842
+ if (source[j] === '\\') {
4843
+ rebuilt += source.slice(j, j + 2);
4844
+ j += 2;
4845
+ continue;
4846
+ }
4847
+ if (source[j] === '`' ) {
4848
+ rebuilt += '`';
4849
+ j++;
4850
+ break;
4851
+ }
4852
+ if (source[j] === '$' && source[j + 1] === '{') {
4853
+ j += 2;
4854
+ const exprStart = j;
4855
+ let braceDepth = 1;
4856
+ while (j < len && braceDepth > 0) {
4857
+ const ec = source[j];
4858
+ const en = source[j + 1];
4859
+ if (ec === '/' && en === '/') {
4860
+ j += 2;
4861
+ while (j < len && source[j] !== '\n') j++;
4862
+ continue;
4863
+ }
4864
+ if (ec === '/' && en === '*') {
4865
+ j += 2;
4866
+ while (j < len && !(source[j] === '*' && source[j + 1] === '/')) j++;
4867
+ j += 2;
4868
+ continue;
4869
+ }
4870
+ if (ec === "'" || ec === '"') {
4871
+ const q = ec;
4872
+ j++;
4873
+ while (j < len && source[j] !== q && source[j] !== '\n') {
4874
+ if (source[j] === '\\') j += 2;
4875
+ else j++;
4876
+ }
4877
+ if (j < len && source[j] === q) j++;
4878
+ continue;
4879
+ }
4880
+ if (ec === '`') {
4881
+ j++;
4882
+ let nestedDepth = 0;
4883
+ while (j < len) {
4884
+ if (source[j] === '\\') { j += 2; continue; }
4885
+ if (source[j] === '$' && source[j + 1] === '{') { nestedDepth++; j += 2; continue; }
4886
+ if (source[j] === '}' && nestedDepth > 0) { nestedDepth--; j++; continue; }
4887
+ if (source[j] === '`' && nestedDepth === 0) { j++; break; }
4888
+ j++;
4889
+ }
4890
+ continue;
4891
+ }
4892
+ if (ec === '{') braceDepth++;
4893
+ else if (ec === '}') {
4894
+ braceDepth--;
4895
+ if (braceDepth === 0) break;
4896
+ }
4897
+ j++;
4898
+ }
4899
+ const rawExpr = source.slice(exprStart, j);
4900
+ const transpiledExpr = isTS
4901
+ ? transpileTS(rawExpr, filename, { expressionOnly: true })
4902
+ : rawExpr;
4903
+ rebuilt += '${' + transpiledExpr + '}';
4904
+ if (j < len && source[j] === '}') j++;
4905
+ continue;
4906
+ }
4907
+ rebuilt += source[j];
4819
4908
  j++;
4820
4909
  }
4821
- code += mask(source.slice(i, j));
4910
+ code += mask(rebuilt);
4822
4911
  i = j;
4823
4912
  continue;
4824
4913
  }
@@ -5192,8 +5281,8 @@ function __initVirtualRuntime(rootScope) {
5192
5281
  };
5193
5282
  code = stripReturnTypes(code);
5194
5283
 
5195
- // Strip parameter type annotations inside `(...)` (supports multi-line parameter lists and default value `()` calls)
5196
- code = code.replace(/\(((?:[^()]|\([^()]*\))*)\)/g, (full, inner) => {
5284
+ // Strip parameter type annotations inside `(...)` from innermost parens outward so nested callbacks work
5285
+ const stripParensParamTypes = (full, inner) => {
5197
5286
  if (!inner.includes(':')) return full;
5198
5287
  if (inner.includes('?') && !/[A-Za-z0-9_$}\]]\s*\?\s*:/.test(inner)) return full;
5199
5288
  if (/[{}]/.test(inner) && !/\}\s*\??\s*:/.test(inner) && !/:\s*[A-Za-z_$][A-Za-z0-9_$.<>[\]|&\s]*\{/.test(inner)) {
@@ -5207,7 +5296,12 @@ function __initVirtualRuntime(rootScope) {
5207
5296
  const parts = splitTopLevel(inner, ',');
5208
5297
  const cleaned = parts.map((part) => cleanSingleParam(part));
5209
5298
  return `(${cleaned.join(',')})`;
5210
- });
5299
+ };
5300
+ do {
5301
+ prevCode = code;
5302
+ code = code.replace(/\(([^()]*)\)/g, stripParensParamTypes);
5303
+ } while (code !== prevCode);
5304
+ code = code.replace(/\(((?:[^()]|\([^()]*\))*)\)/g, stripParensParamTypes);
5211
5305
 
5212
5306
  // Strip variable type annotations: `const x: Type =`, `let y: Type =`
5213
5307
  code = code.replace(/\b(const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*:\s*[^=;\n]+(?<![=!<>])=(?![=>])/g, '$1 $2 =');
@@ -5338,7 +5432,31 @@ function __initVirtualRuntime(rootScope) {
5338
5432
  hasEsmExport = true;
5339
5433
  return `Object.assign(exports, require(${mod.trim()}));`;
5340
5434
  });
5341
- code = code.replace(/\bexport\s+default\s+(async\s+function|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, (_, kw, name) => {
5435
+ const collectBindingIds = (pattern) => {
5436
+ const ids = [];
5437
+ const inner = pattern.trim().replace(/^[\[{]|[\]}]$/g, '');
5438
+ const isObj = pattern.trim().startsWith('{');
5439
+ for (const rawPart of splitTopLevel(inner, ',')) {
5440
+ let part = rawPart.trim();
5441
+ if (!part) continue;
5442
+ if (part.startsWith('...')) {
5443
+ part = part.slice(3).trim();
5444
+ } else if (isObj && part.includes(':')) {
5445
+ const colonIdx = part.indexOf(':');
5446
+ part = part.slice(colonIdx + 1).trim();
5447
+ }
5448
+ const eqIdx = part.indexOf('=');
5449
+ if (eqIdx !== -1) part = part.slice(0, eqIdx).trim();
5450
+ if ((part.startsWith('{') && part.endsWith('}')) || (part.startsWith('[') && part.endsWith(']'))) {
5451
+ ids.push(...collectBindingIds(part));
5452
+ } else if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(part)) {
5453
+ ids.push(part);
5454
+ }
5455
+ }
5456
+ return ids;
5457
+ };
5458
+
5459
+ code = code.replace(/\bexport\s+default\s+(async\s+function\s*\*|function\s*\*|async\s+function|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, (_, kw, name) => {
5342
5460
  hasEsmExport = true;
5343
5461
  defaultExportName = name;
5344
5462
  return `${kw} ${name}`;
@@ -5347,11 +5465,16 @@ function __initVirtualRuntime(rootScope) {
5347
5465
  hasEsmExport = true;
5348
5466
  return 'exports.default = ';
5349
5467
  });
5350
- code = code.replace(/\bexport\s+(async\s+function|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, (_, kw, name) => {
5468
+ code = code.replace(/\bexport\s+(async\s+function\s*\*|function\s*\*|async\s+function|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, (_, kw, name) => {
5351
5469
  hasEsmExport = true;
5352
5470
  exportedNames.push(name);
5353
5471
  return `${kw} ${name}`;
5354
5472
  });
5473
+ code = code.replace(/\bexport\s+(const|let|var)\s+(\{[^;=\n]+\}|\[[^;=\n]+\])\s*=/gm, (_, kw, pat) => {
5474
+ hasEsmExport = true;
5475
+ exportedNames.push(...collectBindingIds(pat));
5476
+ return `${kw} ${pat} =`;
5477
+ });
5355
5478
  code = code.replace(/\bexport\s+(const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)/gm, (_, kw, name) => {
5356
5479
  hasEsmExport = true;
5357
5480
  exportedNames.push(name);
@@ -6483,10 +6606,16 @@ function __initVirtualRuntime(rootScope) {
6483
6606
  const activePortTable = optPortTable || portTable || _defaultPortTable;
6484
6607
  resourceTracker.pid = pid;
6485
6608
 
6486
- let currentCwd = '/workspace';
6609
+ const prevCwdGetter = _activeCwdGetter;
6610
+ let currentCwd = (typeof options.cwd === 'string' && options.cwd.trim())
6611
+ ? VirtualPath.resolve('/workspace', options.cwd.trim())
6612
+ : '/workspace';
6487
6613
  _activeCwdGetter = () => currentCwd;
6488
6614
 
6489
6615
  const vfs = optVfs || createVirtualFs(files, { cwdGetter: () => currentCwd });
6616
+ const initialOpenFds = typeof vfs._listOpenFds === 'function'
6617
+ ? new Set(vfs._listOpenFds())
6618
+ : null;
6490
6619
  if (optVfs && files && typeof files === 'object') {
6491
6620
  for (const [fPath, content] of Object.entries(files)) {
6492
6621
  const abs = fPath.startsWith('/') ? fPath : '/workspace/' + fPath;
@@ -6499,6 +6628,9 @@ function __initVirtualRuntime(rootScope) {
6499
6628
  }
6500
6629
  }
6501
6630
  }
6631
+ if (typeof vfs._setActiveStdin === 'function') {
6632
+ vfs._setActiveStdin(options && options.stdin ? String(options.stdin) : '');
6633
+ }
6502
6634
  const vhttp = createVirtualHttp(resourceTracker, activePortTable);
6503
6635
  const vnet = createVirtualNet(resourceTracker, vhttp.getTrace());
6504
6636
 
@@ -6521,6 +6653,10 @@ function __initVirtualRuntime(rootScope) {
6521
6653
  }
6522
6654
  }
6523
6655
 
6656
+ const initialVfsState = (options && options._captureVfsDiff && typeof vfs._exportRawState === 'function')
6657
+ ? vfs._exportRawState()
6658
+ : null;
6659
+
6524
6660
  // Custom timer wrappers supporting .unref() / .ref() and active handle tracking
6525
6661
  function makeTimerHandle(rawId, isInterval) {
6526
6662
  const handle = {
@@ -6882,7 +7018,7 @@ function __initVirtualRuntime(rootScope) {
6882
7018
  let syncExecDepth = 0;
6883
7019
 
6884
7020
  const sandboxProcess = Object.assign(new EventEmitter(), {
6885
- env: { NODE_ENV: 'development', PATH: '/usr/local/bin:/usr/bin:/bin', HOME: '/home/user' },
7021
+ env: Object.assign({ NODE_ENV: 'development', PATH: '/usr/local/bin:/usr/bin:/bin', HOME: '/home/user' }, options.env || {}),
6886
7022
  argv: argv || ['node', entry.startsWith('/') ? entry : `/workspace/${entry}`],
6887
7023
  argv0: 'node',
6888
7024
  execArgv: [],
@@ -6962,6 +7098,9 @@ function __initVirtualRuntime(rootScope) {
6962
7098
  }
6963
7099
 
6964
7100
  // Immediately cancel all active timers and immediates
7101
+ if (typeof vfs._setActiveStdin === 'function') {
7102
+ vfs._setActiveStdin('');
7103
+ }
6965
7104
  for (const rawId of resourceTracker.allTimers) {
6966
7105
  clearTimeout(rawId);
6967
7106
  clearInterval(rawId);
@@ -8877,6 +9016,9 @@ function __initVirtualRuntime(rootScope) {
8877
9016
  hasExited = true;
8878
9017
  try { sandboxProcess.emit('exit', exitCode); } catch (err) { _runtimeLogger.debug('executeInVirtualRuntime exit listener failed', err); }
8879
9018
  }
9019
+ if (typeof vfs._setActiveStdin === 'function') {
9020
+ vfs._setActiveStdin('');
9021
+ }
8880
9022
  for (const rawId of resourceTracker.allTimers) {
8881
9023
  clearTimeout(rawId);
8882
9024
  clearInterval(rawId);
@@ -8893,12 +9035,56 @@ function __initVirtualRuntime(rootScope) {
8893
9035
  if (!isBackground) {
8894
9036
  vhttp.closeAllServers();
8895
9037
  vnet.closeAllServers();
9038
+ if (initialOpenFds && typeof vfs._listOpenFds === 'function' && typeof vfs.closeSync === 'function') {
9039
+ for (const fd of vfs._listOpenFds()) {
9040
+ if (!initialOpenFds.has(fd)) {
9041
+ try { vfs.closeSync(fd); } catch (err) { _runtimeLogger.debug('executeInVirtualRuntime closeSync leak cleanup failed', { fd, err }); }
9042
+ }
9043
+ }
9044
+ }
8896
9045
  }
9046
+ _activeCwdGetter = prevCwdGetter;
8897
9047
  }
8898
9048
 
8899
9049
  const failedTests = testResults.filter((t) => !t.passed).length;
8900
9050
  if (failedTests > 0 && exitCode === 0) exitCode = 1;
8901
9051
 
9052
+ let vfsChanges = undefined;
9053
+ if (initialVfsState && typeof vfs._exportRawState === 'function') {
9054
+ const finalVfsState = vfs._exportRawState();
9055
+ const modifiedFiles = {};
9056
+ const deletedFiles = [];
9057
+ const createdDirs = [];
9058
+ const isNodeModulesPath = (p) => p === '/workspace/node_modules' || p.startsWith('/workspace/node_modules/');
9059
+ const bytesEqual = (a, b) => {
9060
+ if (!a || !b || a.byteLength !== b.byteLength) return false;
9061
+ for (let i = 0; i < a.byteLength; i++) {
9062
+ if (a[i] !== b[i]) return false;
9063
+ }
9064
+ return true;
9065
+ };
9066
+
9067
+ for (const d of finalVfsState.dirs) {
9068
+ if (!initialVfsState.dirs.has(d) && !isNodeModulesPath(d)) {
9069
+ createdDirs.push(d);
9070
+ }
9071
+ }
9072
+ for (const [fPath, data] of finalVfsState.files.entries()) {
9073
+ if (isNodeModulesPath(fPath)) continue;
9074
+ const prev = initialVfsState.files.get(fPath);
9075
+ if (!prev || !bytesEqual(prev, data)) {
9076
+ modifiedFiles[fPath] = data;
9077
+ }
9078
+ }
9079
+ for (const fPath of initialVfsState.files.keys()) {
9080
+ if (isNodeModulesPath(fPath)) continue;
9081
+ if (!finalVfsState.files.has(fPath)) {
9082
+ deletedFiles.push(fPath);
9083
+ }
9084
+ }
9085
+ vfsChanges = { modifiedFiles, deletedFiles, createdDirs };
9086
+ }
9087
+
8902
9088
  return {
8903
9089
  ok: exitCode === 0,
8904
9090
  exitCode,
@@ -8914,6 +9100,7 @@ function __initVirtualRuntime(rootScope) {
8914
9100
  failed: failedTests
8915
9101
  },
8916
9102
  fsSnapshot: typeof vfs.getSnapshot === 'function' ? vfs.getSnapshot() : [],
9103
+ ...(vfsChanges ? { vfsChanges } : {}),
8917
9104
  httpTrace: [...vhttp.getTrace(), ...vnet.getTrace()],
8918
9105
  replValue: replValue !== undefined ? formatConsoleArg(replValue) : undefined
8919
9106
  };
@@ -9302,14 +9489,70 @@ function __initVirtualRuntime(rootScope) {
9302
9489
 
9303
9490
  exec(sql) {
9304
9491
  const cleaned = stripSqlComments(sql);
9305
- const statements = cleaned.split(';').map((s) => s.trim()).filter(Boolean);
9492
+ const statements = [];
9493
+ let cur = '';
9494
+ let i = 0;
9495
+ while (i < cleaned.length) {
9496
+ const ch = cleaned[i];
9497
+ if (ch === "'" || ch === '"') {
9498
+ const quote = ch;
9499
+ cur += ch;
9500
+ i++;
9501
+ while (i < cleaned.length) {
9502
+ if (cleaned[i] === quote && cleaned[i + 1] === quote) {
9503
+ cur += quote + quote;
9504
+ i += 2;
9505
+ continue;
9506
+ }
9507
+ if (cleaned[i] === '\\' && quote === '"') {
9508
+ cur += cleaned.slice(i, i + 2);
9509
+ i += 2;
9510
+ continue;
9511
+ }
9512
+ cur += cleaned[i];
9513
+ if (cleaned[i] === quote) {
9514
+ i++;
9515
+ break;
9516
+ }
9517
+ i++;
9518
+ }
9519
+ continue;
9520
+ }
9521
+ if (ch === ';') {
9522
+ const trimmed = cur.trim();
9523
+ if (trimmed) statements.push(trimmed);
9524
+ cur = '';
9525
+ i++;
9526
+ continue;
9527
+ }
9528
+ cur += ch;
9529
+ i++;
9530
+ }
9531
+ if (cur.trim()) statements.push(cur.trim());
9306
9532
  for (const s of statements) {
9307
9533
  this.run(s);
9308
9534
  }
9309
9535
  }
9310
9536
 
9311
9537
  transaction(fn) {
9312
- return (...args) => fn(...args);
9538
+ const db = this;
9539
+ return (...args) => {
9540
+ const snapshot = new Map();
9541
+ for (const [tblName, tbl] of db.tables.entries()) {
9542
+ snapshot.set(tblName, {
9543
+ columns: tbl.columns.map((c) => Object.assign({}, c)),
9544
+ rows: tbl.rows.map((r) => Object.assign({}, r)),
9545
+ autoInc: tbl.autoInc
9546
+ });
9547
+ }
9548
+ try {
9549
+ return fn(...args);
9550
+ } catch (err) {
9551
+ db.tables = snapshot;
9552
+ db._persistToVfs();
9553
+ throw err;
9554
+ }
9555
+ };
9313
9556
  }
9314
9557
 
9315
9558
  close() {
@@ -9598,9 +9841,11 @@ function __workerMessageLoop(workerScope) {
9598
9841
  const msg = event.data || {};
9599
9842
  const { requestId, type, payload = {} } = msg;
9600
9843
  if (type !== 'execute') return;
9844
+ workerScope.postMessage({ requestId, type: 'started' });
9601
9845
  try {
9602
9846
  const result = await runtime.executeInVirtualRuntime({
9603
9847
  ...payload,
9848
+ _captureVfsDiff: true,
9604
9849
  onStdout(text) {
9605
9850
  workerScope.postMessage({ requestId, type: 'stdout', text });
9606
9851
  },
@@ -9652,7 +9897,10 @@ function _ensureWorkerUrl() {
9652
9897
  }
9653
9898
 
9654
9899
  function _ensureWarmWorker() {
9655
- if (_warmWorker) return _warmWorker;
9900
+ if (_warmWorker && typeof Worker === 'function' && _warmWorker instanceof Worker) {
9901
+ return _warmWorker;
9902
+ }
9903
+ if (_warmWorker) _destroyWarmWorker();
9656
9904
  _warmWorker = new Worker(_ensureWorkerUrl());
9657
9905
  return _warmWorker;
9658
9906
  }
@@ -9665,6 +9913,14 @@ function _destroyWarmWorker() {
9665
9913
  _warmWorkerBusy = false;
9666
9914
  }
9667
9915
 
9916
+ _hostRuntime.destroyWorkerPool = function destroyWorkerPool() {
9917
+ _destroyWarmWorker();
9918
+ if (_cachedWorkerUrl && typeof URL !== 'undefined' && typeof URL.revokeObjectURL === 'function') {
9919
+ try { URL.revokeObjectURL(_cachedWorkerUrl); } catch (err) { _hostLogger.debug('revokeObjectURL failed', err); }
9920
+ }
9921
+ _cachedWorkerUrl = null;
9922
+ };
9923
+
9668
9924
  _hostRuntime.cancelWorkerExecution = function cancelWorkerExecution(reason = 'Execution cancelled', instanceId) {
9669
9925
  let cancelledAny = false;
9670
9926
  for (const [jobId, job] of Array.from(_activeWorkerJobs.entries())) {
@@ -9677,11 +9933,118 @@ _hostRuntime.cancelWorkerExecution = function cancelWorkerExecution(reason = 'Ex
9677
9933
  return cancelledAny;
9678
9934
  };
9679
9935
 
9936
+ function _extractWorkerFilesFromVfs(vfs) {
9937
+ const extracted = {};
9938
+ if (!vfs || typeof vfs !== 'object') return extracted;
9939
+ try {
9940
+ if (typeof vfs._exportRawState === 'function') {
9941
+ const st = vfs._exportRawState();
9942
+ for (const [absPath, bytes] of st.files.entries()) {
9943
+ extracted[absPath] = bytes;
9944
+ }
9945
+ return extracted;
9946
+ }
9947
+ if (vfs.files instanceof Map) {
9948
+ for (const [absPath, entry] of vfs.files.entries()) {
9949
+ if (!entry) continue;
9950
+ const data = entry.data !== undefined ? entry.data : entry;
9951
+ if (typeof data === 'string') {
9952
+ extracted[absPath] = data;
9953
+ } else if (data instanceof Uint8Array) {
9954
+ extracted[absPath] = data.slice();
9955
+ } else if (ArrayBuffer.isView(data)) {
9956
+ extracted[absPath] = new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
9957
+ }
9958
+ }
9959
+ return extracted;
9960
+ }
9961
+ if (typeof vfs.readdirSync === 'function' && typeof vfs.readFileSync === 'function') {
9962
+ const walk = (dir) => {
9963
+ let entries = [];
9964
+ try { entries = vfs.readdirSync(dir); } catch (_) { return; }
9965
+ for (const name of entries) {
9966
+ const full = dir === '/' ? '/' + name : dir + '/' + name;
9967
+ let isDir = false;
9968
+ try { isDir = vfs.statSync(full).isDirectory(); } catch (_) { isDir = false; }
9969
+ if (isDir) walk(full);
9970
+ else {
9971
+ try {
9972
+ const raw = vfs.readFileSync(full);
9973
+ extracted[full] = raw instanceof Uint8Array
9974
+ ? raw.slice()
9975
+ : (typeof raw === 'string' ? raw : String(raw ?? ''));
9976
+ } catch (err) {
9977
+ _hostLogger.debug('_extractWorkerFilesFromVfs: skip unreadable entry', full, err);
9978
+ }
9979
+ }
9980
+ }
9981
+ };
9982
+ walk('/workspace');
9983
+ walk('/tmp');
9984
+ }
9985
+ } catch (err) {
9986
+ _hostLogger.debug('_extractWorkerFilesFromVfs failed', err);
9987
+ }
9988
+ return extracted;
9989
+ }
9990
+
9991
+ function _applyWorkerVfsChanges(vfs, vfsChanges) {
9992
+ if (!vfs || !vfsChanges || typeof vfsChanges !== 'object') return;
9993
+ const { createdDirs = [], modifiedFiles = {}, deletedFiles = [] } = vfsChanges;
9994
+ try {
9995
+ if (Array.isArray(createdDirs) && typeof vfs.mkdirSync === 'function') {
9996
+ for (const dir of createdDirs) {
9997
+ try {
9998
+ vfs.mkdirSync(dir, { recursive: true });
9999
+ } catch (err) {
10000
+ _hostLogger.debug('_applyWorkerVfsChanges: mkdirSync failed', dir, err);
10001
+ }
10002
+ }
10003
+ }
10004
+ if (modifiedFiles && typeof modifiedFiles === 'object') {
10005
+ for (const [absPath, rawBytes] of Object.entries(modifiedFiles)) {
10006
+ const slashIdx = absPath.lastIndexOf('/');
10007
+ if (slashIdx > 0 && typeof vfs.mkdirSync === 'function') {
10008
+ try {
10009
+ vfs.mkdirSync(absPath.slice(0, slashIdx), { recursive: true });
10010
+ } catch (err) {
10011
+ _hostLogger.debug('_applyWorkerVfsChanges: parent mkdirSync failed', absPath, err);
10012
+ }
10013
+ }
10014
+ const payload = rawBytes instanceof Uint8Array
10015
+ ? rawBytes
10016
+ : (ArrayBuffer.isView(rawBytes)
10017
+ ? new Uint8Array(rawBytes.buffer, rawBytes.byteOffset, rawBytes.byteLength)
10018
+ : rawBytes);
10019
+ if (typeof vfs.writeFileSync === 'function') {
10020
+ vfs.writeFileSync(absPath, payload);
10021
+ } else if (typeof vfs.writeFile === 'function') {
10022
+ vfs.writeFile(absPath, payload);
10023
+ }
10024
+ }
10025
+ }
10026
+ if (Array.isArray(deletedFiles)) {
10027
+ for (const absPath of deletedFiles) {
10028
+ try {
10029
+ if (typeof vfs.unlinkSync === 'function') vfs.unlinkSync(absPath);
10030
+ else if (typeof vfs.rmSync === 'function') vfs.rmSync(absPath, { force: true });
10031
+ } catch (err) {
10032
+ _hostLogger.debug('_applyWorkerVfsChanges: delete failed', absPath, err);
10033
+ }
10034
+ }
10035
+ }
10036
+ } catch (err) {
10037
+ _hostLogger.debug('_applyWorkerVfsChanges failed', err);
10038
+ }
10039
+ }
10040
+
9680
10041
  _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9681
10042
  const isNonJs =
9682
10043
  Boolean(options.wasmBinary) ||
9683
10044
  Boolean(options.cppCompiler) ||
9684
10045
  Boolean(options.pythonCompiler) ||
10046
+ Boolean(options.activePortTable) ||
10047
+ Boolean(options.portTable) ||
9685
10048
  (typeof options.entry === 'string' && /\.(cpp|cc|cxx|wasm|py)$/i.test(options.entry));
9686
10049
  if (
9687
10050
  isNonJs ||
@@ -9701,6 +10064,10 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9701
10064
  _hostRuntime.cancelWorkerExecution('Execution cancelled by new run', instanceId);
9702
10065
  }
9703
10066
 
10067
+ const mergedFiles = options.vfs
10068
+ ? Object.assign(_extractWorkerFilesFromVfs(options.vfs), options.files || {})
10069
+ : options.files;
10070
+
9704
10071
  return new Promise((resolve) => {
9705
10072
  let worker;
9706
10073
  let isWarmWorker = false;
@@ -9719,9 +10086,23 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9719
10086
  return;
9720
10087
  }
9721
10088
 
10089
+ const startTime = typeof performance !== 'undefined' ? performance.now() : Date.now();
9722
10090
  const timeoutMs = options.timeoutMs || 15000;
9723
10091
  let settled = false;
10092
+ let userCodeStarted = false;
9724
10093
  let abortListener = null;
10094
+ const streamedStdoutChunks = [];
10095
+ const streamedStderrChunks = [];
10096
+ const streamedTestResults = [];
10097
+
10098
+ const buildTestSummary = () => {
10099
+ const failed = streamedTestResults.filter((t) => !t.passed).length;
10100
+ return {
10101
+ total: streamedTestResults.length,
10102
+ passed: streamedTestResults.length - failed,
10103
+ failed
10104
+ };
10105
+ };
9725
10106
 
9726
10107
  function releaseWorker(terminateWorker) {
9727
10108
  if (options.signal && abortListener) {
@@ -9748,14 +10129,16 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9748
10129
  if (settled) return;
9749
10130
  settled = true;
9750
10131
  releaseWorker(true);
10132
+ const timeoutMsg = `Execution timed out after ${timeoutMs}ms (infinite loop or hung timer terminated).\n`;
9751
10133
  resolve({
9752
10134
  ok: false,
9753
10135
  timedOut: true,
9754
10136
  exitCode: 124,
9755
10137
  durationMs: timeoutMs,
9756
- stdout: '',
9757
- stderr: `Execution timed out after ${timeoutMs}ms (infinite loop or hung timer terminated).\n`,
9758
- testResults: [],
10138
+ stdout: streamedStdoutChunks.join(''),
10139
+ stderr: streamedStderrChunks.join('') + timeoutMsg,
10140
+ testResults: streamedTestResults.slice(),
10141
+ testSummary: buildTestSummary(),
9759
10142
  fsSnapshot: [],
9760
10143
  httpTrace: [],
9761
10144
  error: { message: `Execution timed out after ${timeoutMs}ms` }
@@ -9770,14 +10153,16 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9770
10153
  settled = true;
9771
10154
  clearTimeout(timer);
9772
10155
  releaseWorker(true);
10156
+ const elapsed = Math.max(0, (typeof performance !== 'undefined' ? performance.now() : Date.now()) - startTime);
9773
10157
  resolve({
9774
10158
  ok: false,
9775
10159
  cancelled: true,
9776
10160
  exitCode: 130,
9777
- durationMs: 0,
9778
- stdout: '',
9779
- stderr: `${reason}\n`,
9780
- testResults: [],
10161
+ durationMs: elapsed,
10162
+ stdout: streamedStdoutChunks.join(''),
10163
+ stderr: streamedStderrChunks.join('') + `${reason}\n`,
10164
+ testResults: streamedTestResults.slice(),
10165
+ testSummary: buildTestSummary(),
9781
10166
  fsSnapshot: [],
9782
10167
  httpTrace: [],
9783
10168
  error: { message: reason }
@@ -9801,16 +10186,27 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9801
10186
  worker.onmessage = (event) => {
9802
10187
  const msg = event.data || {};
9803
10188
  if (msg.requestId !== requestId) return;
9804
- if (msg.type === 'stdout' && typeof options.onStdout === 'function') {
9805
- options.onStdout(msg.text);
9806
- } else if (msg.type === 'stderr' && typeof options.onStderr === 'function') {
9807
- options.onStderr(msg.text);
9808
- } else if (msg.type === 'test-result' && typeof options.onTestResult === 'function') {
9809
- options.onTestResult(msg.testResult);
10189
+ if (msg.type === 'started') {
10190
+ userCodeStarted = true;
10191
+ } else if (msg.type === 'stdout') {
10192
+ userCodeStarted = true;
10193
+ if (typeof msg.text === 'string') streamedStdoutChunks.push(msg.text);
10194
+ if (typeof options.onStdout === 'function') options.onStdout(msg.text);
10195
+ } else if (msg.type === 'stderr') {
10196
+ userCodeStarted = true;
10197
+ if (typeof msg.text === 'string') streamedStderrChunks.push(msg.text);
10198
+ if (typeof options.onStderr === 'function') options.onStderr(msg.text);
10199
+ } else if (msg.type === 'test-result') {
10200
+ userCodeStarted = true;
10201
+ if (msg.testResult) streamedTestResults.push(msg.testResult);
10202
+ if (typeof options.onTestResult === 'function') options.onTestResult(msg.testResult);
9810
10203
  } else if (msg.type === 'complete') {
9811
10204
  if (settled) return;
9812
10205
  settled = true;
9813
10206
  clearTimeout(timer);
10207
+ if (options.vfs && msg.result && msg.result.vfsChanges) {
10208
+ _applyWorkerVfsChanges(options.vfs, msg.result.vfsChanges);
10209
+ }
9814
10210
  // Release `_warmWorker` for instant reuse, or terminate ephemeral concurrent worker
9815
10211
  releaseWorker(false);
9816
10212
  resolve(msg.result);
@@ -9819,13 +10215,16 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9819
10215
  settled = true;
9820
10216
  clearTimeout(timer);
9821
10217
  releaseWorker(false);
10218
+ const elapsed = Math.max(0, (typeof performance !== 'undefined' ? performance.now() : Date.now()) - startTime);
10219
+ const errLine = (msg.error?.stack || msg.error?.message || 'Worker execution error') + '\n';
9822
10220
  resolve({
9823
10221
  ok: false,
9824
10222
  exitCode: 1,
9825
- durationMs: 0,
9826
- stdout: '',
9827
- stderr: (msg.error?.stack || msg.error?.message || 'Worker execution error') + '\n',
9828
- testResults: [],
10223
+ durationMs: elapsed,
10224
+ stdout: streamedStdoutChunks.join(''),
10225
+ stderr: streamedStderrChunks.join('') + errLine,
10226
+ testResults: streamedTestResults.slice(),
10227
+ testSummary: buildTestSummary(),
9829
10228
  fsSnapshot: [],
9830
10229
  httpTrace: [],
9831
10230
  error: { message: msg.error?.message || 'Worker execution error', stack: msg.error?.stack }
@@ -9833,19 +10232,40 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9833
10232
  }
9834
10233
  };
9835
10234
 
9836
- worker.onerror = () => {
10235
+ worker.onerror = (errEvent) => {
9837
10236
  if (settled) return;
9838
10237
  settled = true;
9839
10238
  clearTimeout(timer);
9840
10239
  releaseWorker(true);
9841
- resolve(_hostRuntime.executeInVirtualRuntime(options));
10240
+ // Only fall back to in-process execution if the host blocked Blob Worker startup
10241
+ // BEFORE user code ever started. Never re-run crashed user code on the main thread.
10242
+ if (!userCodeStarted && options.allowMainThreadFallback !== false) {
10243
+ resolve(_hostRuntime.executeInVirtualRuntime(options));
10244
+ return;
10245
+ }
10246
+ const elapsed = Math.max(0, (typeof performance !== 'undefined' ? performance.now() : Date.now()) - startTime);
10247
+ const errMsg = (errEvent && errEvent.message)
10248
+ ? String(errEvent.message)
10249
+ : 'Uncaught fatal error in Web Worker execution';
10250
+ resolve({
10251
+ ok: false,
10252
+ exitCode: 1,
10253
+ durationMs: elapsed,
10254
+ stdout: streamedStdoutChunks.join(''),
10255
+ stderr: streamedStderrChunks.join('') + errMsg + '\n',
10256
+ testResults: streamedTestResults.slice(),
10257
+ testSummary: buildTestSummary(),
10258
+ fsSnapshot: [],
10259
+ httpTrace: [],
10260
+ error: { message: errMsg }
10261
+ });
9842
10262
  };
9843
10263
 
9844
10264
  worker.postMessage({
9845
10265
  requestId,
9846
10266
  type: 'execute',
9847
10267
  payload: {
9848
- files: options.files,
10268
+ files: mergedFiles,
9849
10269
  entry: options.entry,
9850
10270
  mode: options.mode,
9851
10271
  replCode: options.replCode,
@@ -9861,7 +10281,8 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
9861
10281
  printReplResult: options.printReplResult,
9862
10282
  stdin: options.stdin,
9863
10283
  wasmBinary: options.wasmBinary,
9864
- env: options.env
10284
+ env: options.env,
10285
+ cwd: options.cwd
9865
10286
  }
9866
10287
  });
9867
10288
  });
@@ -9911,6 +10332,7 @@ const createSqliteDatabase = CodeLabRuntime.createSqliteDatabase;
9911
10332
  const executeInVirtualRuntime = CodeLabRuntime.executeInVirtualRuntime;
9912
10333
  const createWorkerRuntimeSource = CodeLabRuntime.createWorkerRuntimeSource;
9913
10334
  const cancelWorkerExecution = CodeLabRuntime.cancelWorkerExecution;
10335
+ const destroyWorkerPool = CodeLabRuntime.destroyWorkerPool;
9914
10336
  const executeInWorker = CodeLabRuntime.executeInWorker;
9915
10337
 
9916
10338
  export {
@@ -9943,6 +10365,7 @@ export {
9943
10365
  executeInVirtualRuntime,
9944
10366
  createWorkerRuntimeSource,
9945
10367
  cancelWorkerExecution,
10368
+ destroyWorkerPool,
9946
10369
  executeInWorker
9947
10370
  };
9948
10371
  export default CodeLabRuntime;