@innovatorved/code-lab 0.6.1 → 0.7.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 (46) hide show
  1. package/ARCHITECTURE.md +1 -1
  2. package/CHANGELOG.md +15 -0
  3. package/README.md +38 -1
  4. package/dist/code-lab-sql.esm.js +1 -1
  5. package/dist/code-lab-sql.umd.js +2 -2
  6. package/dist/code-lab.css +1 -1
  7. package/dist/code-lab.d.ts +19 -1
  8. package/dist/code-lab.esm.js +712 -704
  9. package/dist/code-lab.js +711 -703
  10. package/dist/code-lab.umd.js +711 -703
  11. package/dist/extensions/cpp.esm.js +9 -0
  12. package/dist/extensions/cpp.js +9 -0
  13. package/dist/extensions/guided-lab.esm.js +9 -0
  14. package/dist/extensions/guided-lab.js +9 -0
  15. package/dist/extensions/python.esm.js +9 -0
  16. package/dist/extensions/python.js +9 -0
  17. package/dist/index.d.ts +1 -1
  18. package/dist/preview-sw.js +1 -1
  19. package/dist/runtime.esm.js +70 -70
  20. package/dist/runtime.js +70 -70
  21. package/dist/schemas.d.ts +13 -1
  22. package/dist/schemas.esm.js +9 -0
  23. package/dist/schemas.js +9 -0
  24. package/dist/shell.esm.js +250 -244
  25. package/dist/shell.js +250 -244
  26. package/dist/terminal.esm.js +1 -1
  27. package/dist/terminal.js +1 -1
  28. package/package.json +1 -1
  29. package/packages/commands/package.json +1 -1
  30. package/packages/core/package.json +1 -1
  31. package/packages/editor/package.json +1 -1
  32. package/packages/fs/package.json +1 -1
  33. package/packages/preview/package.json +1 -1
  34. package/packages/runtime/package.json +1 -1
  35. package/packages/settings/package.json +1 -1
  36. package/packages/settings/src/builtin-schemas.ts +16 -0
  37. package/packages/sql/package.json +1 -1
  38. package/packages/terminal/package.json +1 -1
  39. package/packages/ui/package.json +1 -1
  40. package/packages/ui/src/settings-dialog.ts +30 -2
  41. package/src/code-lab.css +7 -1
  42. package/src/index.ts +1 -1
  43. package/src/runtime.ts +29 -3
  44. package/src/schemas.ts +10 -1
  45. package/src/shell.ts +106 -16
  46. package/src/workbench.ts +365 -82
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.6.1 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.7.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
package/dist/terminal.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.6.1 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.7.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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innovatorved/code-lab",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Modular browser-native IDE Workbench, Lightweight SQL Playground & Inline Editor (@innovatorved/code-lab/sql), POSIX Shell & Coreutils, PTY Terminal, Web Worker Node.js/Bun Virtual Runtime, C++20 WASI, and Python 3.12 Extension.",
5
5
  "workspaces": [
6
6
  "packages/*",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-lab/commands",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "CommandRegistry, VS Code-style ContextKeyService (when-clause evaluator), and KeybindingService for CodeLab.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-lab/core",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Zero-DOM foundational primitives for CodeLab: ServiceContainer DI, IDisposable/DisposableStore, typed Emitter/Event bus, CodeLabError/Logger, ContributionRegistry, and POSIX path/glob utilities.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-lab/editor",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Swappable editor service and IEditorAdapter implementations (Monaco, SQL, Lightweight textarea) for CodeLab.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-lab/fs",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Pluggable virtual filesystem service for CodeLab with Memory, IndexedDB, and OPFS backends.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-lab/preview",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Isolated web preview service, iframe sandbox enforcer, and CSP builder for CodeLab.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-lab/runtime",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Typed sandbox execution service & worker host supervisor for CodeLab.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-lab/settings",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Layered configuration service (defaults -> user -> .codelab/settings.json -> URL/embed), JSONC parser, and CSP-safe JSON Schema validator.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -83,6 +83,22 @@ export const BUILTIN_SETTINGS: readonly SettingDescriptor[] = [
83
83
  defaultValue: true,
84
84
  schema: { type: 'boolean', default: true }
85
85
  },
86
+ {
87
+ key: 'workbench.sidebar.defaultLocation',
88
+ category: 'Workbench',
89
+ title: 'Sidebar Location',
90
+ description: 'Controls whether the primary sidebar is docked on the left or right.',
91
+ defaultValue: 'left',
92
+ schema: { type: 'string', enum: ['left', 'right'], default: 'left' }
93
+ },
94
+ {
95
+ key: 'workbench.statusBar.visible',
96
+ category: 'Workbench',
97
+ title: 'Status Bar Visible',
98
+ description: 'Controls the visibility of the status bar at the bottom of the workbench.',
99
+ defaultValue: true,
100
+ schema: { type: 'boolean', default: true }
101
+ },
86
102
  {
87
103
  key: 'workbench.panel.defaultTab',
88
104
  category: 'Workbench',
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-lab/sql",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Zero-dependency lightweight SQL editor & PostgreSQL 18 / SQLite 3 language pack (<35 KB gzipped) with schema-aware alias autocomplete, formatter, and inline error diagnostics.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-lab/terminal",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Typed multi-session terminal service & ANSI stream parser for CodeLab.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-lab/ui",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Workbench UI services and components for CodeLab: ThemeService (dark/light/high-contrast/custom), Searchable Settings Dialog, Quick Open, PluginRegistry, ErrorBoundary, and Dev Observability Inspector.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -623,19 +623,41 @@ export class SettingsDialogController implements IDisposable {
623
623
  nextValue = el.value;
624
624
  }
625
625
 
626
+ let applied = false;
626
627
  if (hasValidValue) {
627
628
  if (this.activeScope === 'workspace') {
628
- if (this.config.setWorkspaceSetting(key, nextValue)) {
629
+ applied = this.config.setWorkspaceSetting(key, nextValue);
630
+ if (applied) {
629
631
  this.notifyWorkspaceMutated(mode);
630
632
  }
631
633
  } else {
632
634
  const hadWorkspaceOverride = this.config.inspect(key).workspaceValue !== undefined;
633
- if (this.config.setUserSetting(key, nextValue) && hadWorkspaceOverride) {
635
+ applied = this.config.setUserSetting(key, nextValue);
636
+ if (applied && hadWorkspaceOverride) {
634
637
  this.config.setWorkspaceSetting(key, nextValue);
635
638
  this.notifyWorkspaceMutated(mode);
636
639
  }
637
640
  }
638
641
  }
642
+ if (!applied) {
643
+ const min = desc.schema.minimum;
644
+ const max = desc.schema.maximum;
645
+ const rangeHint =
646
+ min !== undefined && max !== undefined
647
+ ? `Value must be between ${min} and ${max}.`
648
+ : min !== undefined
649
+ ? `Value must be at least ${min}.`
650
+ : max !== undefined
651
+ ? `Value must be at most ${max}.`
652
+ : 'Invalid setting value.';
653
+ if ('setCustomValidity' in el && typeof (el as HTMLInputElement).setCustomValidity === 'function') {
654
+ (el as HTMLInputElement).setCustomValidity(rangeHint);
655
+ if (typeof (el as HTMLInputElement).reportValidity === 'function') {
656
+ (el as HTMLInputElement).reportValidity();
657
+ }
658
+ (el as HTMLInputElement).setCustomValidity('');
659
+ }
660
+ }
639
661
  this.renderAllActiveSurfaces('items');
640
662
  };
641
663
  surfaceEl.addEventListener('change', onChange);
@@ -872,6 +894,9 @@ export class SettingsDialogController implements IDisposable {
872
894
  ? (insp.workspaceValue !== undefined ? 'workspace' : '')
873
895
  : (insp.effectiveSource !== 'default' ? insp.effectiveSource : '');
874
896
 
897
+ const hasWorkspaceOverrideNotice =
898
+ this.activeScope === 'user' && insp.workspaceValue !== undefined;
899
+
875
900
  const modClass = canReset ? ' cl-setting-item--modified' : '';
876
901
 
877
902
  return (
@@ -884,6 +909,9 @@ export class SettingsDialogController implements IDisposable {
884
909
  (badgeLabel
885
910
  ? `<span class="cl-setting-badge" data-role="setting-badge">${escapeAttr(badgeLabel)}</span>`
886
911
  : '') +
912
+ (hasWorkspaceOverrideNotice
913
+ ? `<span class="cl-setting-badge" data-role="setting-workspace-override" title="Overridden in .codelab/settings.json">Modified in Workspace</span>`
914
+ : '') +
887
915
  `</div>` +
888
916
  (canReset
889
917
  ? `<button type="button" class="codelab-btn cl-ui-btn" data-reset-key="${escapeAttr(desc.key)}" title="Reset to Default (${escapeAttr(JSON.stringify(desc.defaultValue))})">Reset</button>`
package/src/code-lab.css CHANGED
@@ -314,6 +314,11 @@ code-lab,
314
314
  border: none !important;
315
315
  }
316
316
 
317
+ .codelab.is-zen-mode .codelab-statusbar,
318
+ .codelab.is-zen-mode .codelab-activitybar {
319
+ display: none !important;
320
+ }
321
+
317
322
  /* ── Top Workbench Titlebar (35px VS Code Titlebar) ── */
318
323
  .codelab-topbar,
319
324
  .codelab-titlebar,
@@ -1412,7 +1417,8 @@ code-lab,
1412
1417
  background: var(--cl-bg-hover);
1413
1418
  }
1414
1419
 
1415
- .codelab-folder-item.drag-over {
1420
+ .codelab-folder-item.drag-over,
1421
+ .codelab-explorer.drag-over {
1416
1422
  background: var(--cl-bg-hover);
1417
1423
  outline: 1px dashed var(--cl-focus-border);
1418
1424
  outline-offset: -1px;
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @innovatorved/code-lab v0.6.1
2
+ * @innovatorved/code-lab v0.7.0
3
3
  * Browser-native IDE, POSIX Shell, Web Worker Node.js/Bun Runtime, WASI C++20 Toolchain, Python 3.12 WebAssembly, and Git Engine.
4
4
  */
5
5
 
package/src/runtime.ts CHANGED
@@ -7714,6 +7714,8 @@ function __initVirtualRuntime(rootScope) {
7714
7714
  return isDeepEqual(a, b, true);
7715
7715
  }
7716
7716
 
7717
+ const activeBunServers = new Set();
7718
+
7717
7719
  const BunObj = {
7718
7720
  version: '1.1.0',
7719
7721
  serve(opts = {}) {
@@ -7724,6 +7726,7 @@ function __initVirtualRuntime(rootScope) {
7724
7726
  hostname,
7725
7727
  development: false,
7726
7728
  stop() {
7729
+ activeBunServers.delete(serverObj);
7727
7730
  activePortTable.unregisterServer(port);
7728
7731
  }
7729
7732
  };
@@ -7735,6 +7738,7 @@ function __initVirtualRuntime(rootScope) {
7735
7738
  fetch: opts.fetch ? opts.fetch.bind(serverObj) : undefined,
7736
7739
  stop: () => serverObj.stop()
7737
7740
  });
7741
+ activeBunServers.add(serverObj);
7738
7742
  return serverObj;
7739
7743
  },
7740
7744
  file(p) {
@@ -9012,13 +9016,31 @@ function __initVirtualRuntime(rootScope) {
9012
9016
  }
9013
9017
  }
9014
9018
 
9019
+ const hasLiveServers = () => {
9020
+ if (vhttp.hasActiveServers()) return true;
9021
+ if (activeBunServers.size > 0) {
9022
+ for (const srv of Array.from(activeBunServers)) {
9023
+ if (!activePortTable.getServer(srv.port)) {
9024
+ activeBunServers.delete(srv);
9025
+ }
9026
+ }
9027
+ return activeBunServers.size > 0;
9028
+ }
9029
+ return false;
9030
+ };
9031
+
9015
9032
  const deadline = performance.now() + timeoutMs;
9016
9033
  let idleTicks = 0;
9017
- while (!hasExited && performance.now() < deadline) {
9034
+ while (!hasExited) {
9018
9035
  if (signal && signal.aborted) {
9019
9036
  handleSigint();
9020
9037
  break;
9021
9038
  }
9039
+ const liveServers = hasLiveServers();
9040
+ const holdForInteractiveServer = Boolean(!isBackground && signal && liveServers);
9041
+ if (!holdForInteractiveServer && performance.now() >= deadline) {
9042
+ break;
9043
+ }
9022
9044
  await Promise.resolve();
9023
9045
  await Promise.resolve();
9024
9046
  const busy =
@@ -9026,7 +9048,7 @@ function __initVirtualRuntime(rootScope) {
9026
9048
  resourceTracker.activeImmediates.size > 0 ||
9027
9049
  resourceTracker.inFlightHttp.size > 0 ||
9028
9050
  resourceTracker.pendingTests.size > 0 ||
9029
- (isBackground && vhttp.hasActiveServers());
9051
+ ((isBackground || Boolean(signal)) && liveServers);
9030
9052
 
9031
9053
  if (!busy) {
9032
9054
  idleTicks++;
@@ -9034,7 +9056,7 @@ function __initVirtualRuntime(rootScope) {
9034
9056
  } else {
9035
9057
  idleTicks = 0;
9036
9058
  }
9037
- await new Promise((r) => setTimeout(r, 2));
9059
+ await new Promise((r) => setTimeout(r, holdForInteractiveServer ? 25 : 2));
9038
9060
  }
9039
9061
  } catch (err) {
9040
9062
  if (err && err._isProcessExit) {
@@ -9070,6 +9092,10 @@ function __initVirtualRuntime(rootScope) {
9070
9092
  if (!isBackground) {
9071
9093
  vhttp.closeAllServers();
9072
9094
  vnet.closeAllServers();
9095
+ for (const srv of Array.from(activeBunServers)) {
9096
+ try { srv.stop(); } catch (err) { _runtimeLogger.debug('executeInVirtualRuntime bun server stop failed', err); }
9097
+ }
9098
+ activeBunServers.clear();
9073
9099
  if (initialOpenFds && typeof vfs._listOpenFds === 'function' && typeof vfs.closeSync === 'function') {
9074
9100
  for (const fd of vfs._listOpenFds()) {
9075
9101
  if (!initialOpenFds.has(fd)) {
package/src/schemas.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as z from 'zod';
2
2
 
3
3
  /**
4
- * Zod Schemas and Inferred TypeScript Types for code-lab v0.6.1
4
+ * Zod Schemas and Inferred TypeScript Types for code-lab v0.7.0
5
5
  */
6
6
 
7
7
  // ── 1. Guided Step ──────────────────────────────────────────────────────────
@@ -259,6 +259,15 @@ export const WorkbenchOptionsSchema = z.object({
259
259
  mode: z.enum(['guided', 'sandbox']).optional(),
260
260
  language: LanguageIdSchema.optional(),
261
261
  lang: LanguageIdSchema.optional(),
262
+ showLanguageSelector: z.boolean().optional(),
263
+ sqlDialect: z.enum(['postgres', 'sqlite']).optional(),
264
+ sqlFiles: z.record(z.string(), z.string()).optional(),
265
+ settings: z.record(z.string(), z.any()).optional(),
266
+ userSettings: z.record(z.string(), z.any()).optional(),
267
+ defaultSettings: z.record(z.string(), z.any()).optional(),
268
+ config: z.record(z.string(), z.any()).optional(),
269
+ overrides: z.record(z.string(), z.any()).optional(),
270
+ lockSettings: z.boolean().optional(),
262
271
  stepIndex: z.number().int().optional(),
263
272
  onStepComplete: z.function({ input: [z.any(), z.number()], output: z.void() }).optional(),
264
273
  onLabComplete: z.function({ input: [z.string()], output: z.void() }).optional()
package/src/shell.ts CHANGED
@@ -3535,7 +3535,7 @@
3535
3535
  if (scriptArgs && scriptArgs.length > 0) {
3536
3536
  cmd += ' ' + scriptArgs.map(quoteShellArg).join(' ');
3537
3537
  }
3538
- const fallback = tryDevScriptFallback(scriptName, cmd, ctx);
3538
+ const fallback = await tryDevScriptFallback(scriptName, cmd, ctx);
3539
3539
  if (fallback) return fallback;
3540
3540
  const binPrefix = `${PosixPath.join(ctx.cwd || '/workspace', 'node_modules/.bin')}:/workspace/node_modules/.bin`;
3541
3541
  const scriptEnv = {
@@ -3547,6 +3547,7 @@
3547
3547
  env: scriptEnv,
3548
3548
  stdin: ctx.stdin,
3549
3549
  signal: ctx.signal,
3550
+ isBackground: ctx.isBackground,
3550
3551
  onStdout: ctx.onStdout,
3551
3552
  onStderr: ctx.onStderr,
3552
3553
  onRequestStdin: ctx.onRequestStdin || (ctx.shell && ctx.shell.options ? ctx.shell.options.onRequestStdin : undefined)
@@ -4100,31 +4101,96 @@
4100
4101
  // Common dev-server commands that cannot run inside the virtual runtime are
4101
4102
  // transparently redirected to the built-in preview server.
4102
4103
  const PREVIEW_TOOL_RE = /\b(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts|serve|http-server)\b/;
4104
+ const NATIVE_DEV_SERVER_RE = /^(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts)$/;
4103
4105
  // The same tools, when typed directly at the prompt (`ng serve`, `vite`).
4104
4106
  // `serve` is omitted: it is a first-class builtin shell command.
4105
4107
  const DIRECT_DEV_TOOL_RE = /^(vite|ng|astro|next|webpack|parcel|esbuild|snowpack|react-scripts|http-server)$/;
4106
4108
 
4107
- function tryDevScriptFallback(scriptName, cmd, ctx, opts) {
4109
+ /**
4110
+ * Holds a foreground interactive server command open until Ctrl+C (SIGINT)
4111
+ * or external port shutdown, unregistering the port cleanly on interrupt.
4112
+ */
4113
+ async function waitForForegroundServer(entry, ctx, banner) {
4114
+ const portTable = ctx && ctx.shell ? ctx.shell.portTable : null;
4115
+ const isInteractiveFg = Boolean(ctx && !ctx.isBackground && ctx.signal);
4116
+ if (!isInteractiveFg) {
4117
+ return { code: 0, stdout: banner, stderr: '' };
4118
+ }
4119
+
4120
+ const fullBanner = `${banner.replace(/\n+$/, '')}\n ➜ Press Ctrl+C to stop\n\n`;
4121
+ if (typeof ctx.onStdout === 'function') {
4122
+ ctx.onStdout(fullBanner);
4123
+ }
4124
+
4125
+ const closeServer = () => {
4126
+ if (entry && entry.server && typeof entry.server.close === 'function') {
4127
+ try { entry.server.close(); } catch (err) { _shellLogger.debug('Foreground server close failed.', err); }
4128
+ } else if (portTable && typeof portTable.unregisterServer === 'function' && entry) {
4129
+ try { portTable.unregisterServer(entry.port); } catch (err) { _shellLogger.debug('Foreground server unregister failed.', err); }
4130
+ }
4131
+ };
4132
+
4133
+ if (ctx.signal.aborted) {
4134
+ closeServer();
4135
+ return { code: 130, stdout: fullBanner, stderr: '', alreadyStreamed: typeof ctx.onStdout === 'function', aborted: true };
4136
+ }
4137
+
4138
+ return await new Promise((resolve) => {
4139
+ let settled = false;
4140
+ const cleanup = () => {
4141
+ if (ctx.signal && typeof ctx.signal.removeEventListener === 'function') {
4142
+ try { ctx.signal.removeEventListener('abort', onAbort); } catch (_) { void _; }
4143
+ }
4144
+ if (portTable && typeof portTable.off === 'function') {
4145
+ try { portTable.off('close', onPortClose); } catch (_) { void _; }
4146
+ }
4147
+ };
4148
+ const finish = (code, aborted) => {
4149
+ if (settled) return;
4150
+ settled = true;
4151
+ cleanup();
4152
+ resolve({
4153
+ code,
4154
+ stdout: fullBanner,
4155
+ stderr: '',
4156
+ alreadyStreamed: typeof ctx.onStdout === 'function',
4157
+ aborted
4158
+ });
4159
+ };
4160
+ const onAbort = () => {
4161
+ closeServer();
4162
+ finish(130, true);
4163
+ };
4164
+ const onPortClose = (closedPort, closedEntry) => {
4165
+ if (entry && Number(closedPort) === Number(entry.port) && (!closedEntry || closedEntry === entry)) {
4166
+ finish(0, false);
4167
+ }
4168
+ };
4169
+ ctx.signal.addEventListener('abort', onAbort, { once: true });
4170
+ if (portTable && typeof portTable.on === 'function') {
4171
+ portTable.on('close', onPortClose);
4172
+ }
4173
+ });
4174
+ }
4175
+
4176
+ async function tryDevScriptFallback(scriptName, cmd, ctx, opts) {
4108
4177
  if (!PREVIEW_TOOL_RE.test(cmd)) return null;
4109
- // Only fall back when the referenced tool is not actually installed.
4110
4178
  const bin = (cmd.match(PREVIEW_TOOL_RE) || [])[1];
4111
4179
  const force = Boolean(opts && opts.force);
4112
4180
  const binPath = PosixPath.join('/workspace/node_modules/.bin', bin);
4113
- if (!force && ctx.vfs.existsSync(binPath)) return null;
4181
+ const isInstalled = ctx.vfs.existsSync(binPath);
4182
+ if (!force && !NATIVE_DEV_SERVER_RE.test(bin) && isInstalled) return null;
4114
4183
  const portMatch = cmd.match(/--port(?:=|\s+)(\d+)/);
4115
4184
  const defaultPorts = { ng: 4200, vite: 5173, astro: 4321, next: 3000 };
4116
4185
  const port = portMatch ? Number(portMatch[1]) : (defaultPorts[bin] || 3000);
4117
4186
  const rootDir = typeof ctx.resolvePath === 'function' ? ctx.resolvePath('.') : (ctx.cwd || '/workspace');
4118
4187
  const entry = registerPreviewServer(ctx, rootDir, port);
4119
4188
  if (!entry) return null;
4120
- const note = force
4189
+ const note = (force || isInstalled)
4121
4190
  ? `${bin} is a native dev server and cannot execute inside this virtual runtime — using the CodeLab preview server instead.`
4122
4191
  : `${bin} is not available in this virtual runtime — using the CodeLab preview server instead.`;
4123
- return {
4124
- code: 0,
4125
- stdout: `\n> ${scriptName}\n> ${cmd}\n\n ${note}\n\n ➜ Local: http://127.0.0.1:${entry.port}/\n\n`,
4126
- stderr: ''
4127
- };
4192
+ const banner = `\n> ${scriptName}\n> ${cmd}\n\n ${note}\n\n ➜ Local: http://127.0.0.1:${entry.port}/\n\n`;
4193
+ return await waitForForegroundServer(entry, ctx, banner);
4128
4194
  }
4129
4195
 
4130
4196
  function evaluatePosixTest(args, ctx) {
@@ -7625,6 +7691,33 @@
7625
7691
  return { code: 0, stdout: 'Python 3.12.8 (CPython WebAssembly via Pyodide)\n', stderr: '' };
7626
7692
  }
7627
7693
 
7694
+ if (args[0] === '-m' && args[1] === 'http.server') {
7695
+ let port = 8000;
7696
+ let dirArg = '.';
7697
+ for (let i = 2; i < args.length; i++) {
7698
+ const a = args[i];
7699
+ if ((a === '-d' || a === '--directory') && args[i + 1]) {
7700
+ dirArg = args[++i];
7701
+ } else if (a.startsWith('--directory=')) {
7702
+ dirArg = a.slice('--directory='.length) || '.';
7703
+ } else if (a === '-b' || a === '--bind') {
7704
+ i++;
7705
+ } else if (/^\d+$/.test(a)) {
7706
+ port = Number(a);
7707
+ }
7708
+ }
7709
+ const rootDir = ctx.resolvePath(dirArg);
7710
+ if (!ctx.vfs.existsSync(rootDir)) {
7711
+ return { code: 1, stdout: '', stderr: `python3: http.server: ${dirArg}: No such file or directory\n` };
7712
+ }
7713
+ const entry = registerPreviewServer(ctx, rootDir, port);
7714
+ if (!entry) {
7715
+ return { code: 1, stdout: '', stderr: 'python3: http.server: no virtual port table available\n' };
7716
+ }
7717
+ const banner = `Serving HTTP on 127.0.0.1 port ${entry.port} (http://127.0.0.1:${entry.port}/) ...\n`;
7718
+ return await waitForForegroundServer(entry, ctx, banner);
7719
+ }
7720
+
7628
7721
  const pyCompiler =
7629
7722
  (ctx.shell && ctx.shell.options && ctx.shell.options.pythonCompiler) ||
7630
7723
  (typeof globalThis !== 'undefined' && globalThis.__codelabPythonCompiler) ||
@@ -8249,11 +8342,8 @@
8249
8342
  if (!entry) {
8250
8343
  return { code: 1, stdout: '', stderr: 'serve: no virtual port table available\n' };
8251
8344
  }
8252
- return {
8253
- code: 0,
8254
- stdout: `\n ⚡ CodeLab preview server\n\n ➜ Local: http://127.0.0.1:${entry.port}/\n ➜ Root: ${rootDir}\n ➜ Preview: open the Web Preview drawer for port ${entry.port}\n\n`,
8255
- stderr: ''
8256
- };
8345
+ const banner = `\n ⚡ CodeLab preview server\n\n ➜ Local: http://127.0.0.1:${entry.port}/\n ➜ Root: ${rootDir}\n ➜ Preview: open the Web Preview drawer for port ${entry.port}\n\n`;
8346
+ return await waitForForegroundServer(entry, ctx, banner);
8257
8347
  },
8258
8348
 
8259
8349
  // -----------------------------------------------------------------------
@@ -10803,7 +10893,7 @@
10803
10893
  // this runtime — whether or not it was installed — so route it to the
10804
10894
  // built-in preview server rather than reporting a misleading "command
10805
10895
  // not found".
10806
- const fb = tryDevScriptFallback(cmdName, [cmdName, ...args].join(' '), cmdCtx, { force: true });
10896
+ const fb = await tryDevScriptFallback(cmdName, [cmdName, ...args].join(' '), cmdCtx, { force: true });
10807
10897
  res = fb || { code: 127, stdout: '', stderr: `shell: ${cmdName}: command not found\n` };
10808
10898
  } else if (typeof this.options.onProcessSpawn === 'function') {
10809
10899
  const spawned = await this.options.onProcessSpawn(cmdName, args, {