@innovatorved/code-lab 0.1.2 → 0.1.4

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/src/workbench.js CHANGED
@@ -1171,6 +1171,9 @@ declare module 'bun:sqlite' {
1171
1171
  this.folders = new Set(this.savedState?.folders || []);
1172
1172
  this.collapsedFolders = new Set(this.savedState?.collapsedFolders || []);
1173
1173
  this.explorerFolder = this.savedState?.explorerFolder || ''; // '' = workspace root, else folder path scope
1174
+ this.explorerWidth = (typeof this.savedState?.explorerWidth === 'number' && this.savedState.explorerWidth >= 120)
1175
+ ? this.savedState.explorerWidth
1176
+ : 196;
1174
1177
  this.folderSwitcherOpen = false;
1175
1178
  this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
1176
1179
  this.renamingItem = null;
@@ -1508,7 +1511,8 @@ declare module 'bun:sqlite' {
1508
1511
  activeFile: this.activeFile,
1509
1512
  folders: Array.from(this.folders || []),
1510
1513
  collapsedFolders: Array.from(this.collapsedFolders || []),
1511
- explorerFolder: this.explorerFolder || ''
1514
+ explorerFolder: this.explorerFolder || '',
1515
+ explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined
1512
1516
  };
1513
1517
  this.savedState = state;
1514
1518
  if (this.options && this.options.persistState === false) {
@@ -1689,6 +1693,13 @@ declare module 'bun:sqlite' {
1689
1693
  if (stopBtn) {
1690
1694
  stopBtn.style.display = this.isRunning ? 'inline-flex' : 'none';
1691
1695
  }
1696
+ const ctrlCBtn = this.container.querySelector('#cl-ctrl-c-btn');
1697
+ if (ctrlCBtn) {
1698
+ ctrlCBtn.classList.toggle('is-running', Boolean(this.isRunning));
1699
+ ctrlCBtn.title = this.isRunning
1700
+ ? 'Send Ctrl+C — interrupt the running command'
1701
+ : 'Send Ctrl+C (clears the current input line)';
1702
+ }
1692
1703
  this.container.querySelectorAll('[data-cl-action="run-demo"], [data-cl-action="run-tests"], [data-cl-action="verify-step"]').forEach(btn => {
1693
1704
  btn.disabled = this.isRunning;
1694
1705
  });
@@ -1703,8 +1714,9 @@ declare module 'bun:sqlite' {
1703
1714
  const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
1704
1715
  const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
1705
1716
  const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
1717
+ const explorerStyle = `style="--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px"`;
1706
1718
  this.container.innerHTML = `
1707
- <div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr}>
1719
+ <div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
1708
1720
  <!-- Top Bar -->
1709
1721
  <div class="codelab-topbar codelab-toolbar">
1710
1722
  <div class="codelab-topbar__left">
@@ -1820,6 +1832,9 @@ declare module 'bun:sqlite' {
1820
1832
  <div class="codelab-explorer__list" id="cl-explorer-list"></div>
1821
1833
  </div>
1822
1834
 
1835
+ <!-- Explorer Resize Splitter -->
1836
+ <div class="codelab-splitter-files" id="cl-splitter-files" role="separator" aria-orientation="vertical" title="Drag to resize file explorer (double-click to reset)"></div>
1837
+
1823
1838
  <!-- Editor Column -->
1824
1839
  <div class="codelab-editor-col">
1825
1840
  <div class="codelab-tabs codelab-file-tabs" id="cl-file-tabs" role="tablist" aria-label="Open Files"></div>
@@ -1873,6 +1888,7 @@ declare module 'bun:sqlite' {
1873
1888
  </button>
1874
1889
  </div>
1875
1890
  <div style="display:flex;align-items:center;gap:6px;">
1891
+ <button type="button" class="codelab-btn codelab-btn--icon codelab-btn--ctrl-c" id="cl-ctrl-c-btn" data-cl-action="interrupt" title="Send Ctrl+C — interrupt a running command" aria-label="Send Ctrl+C interrupt" style="padding:2px 8px;font-size:11px;font-family:var(--cl-font-mono);">Ctrl+C</button>
1876
1892
  <button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="clear-terminal" title="Clear Output" style="padding:2px 6px;font-size:11px;">Clear</button>
1877
1893
  <button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="toggle-drawer" title="Minimize/Expand Drawer" aria-label="Minimize or Expand Drawer" style="padding:2px 6px;font-size:11px;">${CL_ICONS.chevronsUpDown}</button>
1878
1894
  </div>
@@ -3014,10 +3030,10 @@ declare module 'bun:sqlite' {
3014
3030
  this._ptyInputAfterCursor = '';
3015
3031
  this._updatePtyActiveLine();
3016
3032
  }
3017
- } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c') {
3033
+ } else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'c') {
3018
3034
  e.preventDefault();
3019
3035
  this._handleInterrupt();
3020
- } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'd') {
3036
+ } else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'd') {
3021
3037
  e.preventDefault();
3022
3038
  if (this.inRepl) {
3023
3039
  this.inRepl = false;
@@ -3026,7 +3042,7 @@ declare module 'bun:sqlite' {
3026
3042
  const nextInput = this.container.querySelector('#cl-repl-input');
3027
3043
  if (nextInput && typeof nextInput.focus === 'function') nextInput.focus();
3028
3044
  }
3029
- } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'l') {
3045
+ } else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'l') {
3030
3046
  e.preventDefault();
3031
3047
  this.terminalLogs = [];
3032
3048
  this._renderDrawerBody();
@@ -4771,41 +4787,18 @@ declare module 'bun:sqlite' {
4771
4787
 
4772
4788
  _renderEmptyEditorContent(emptyEl) {
4773
4789
  if (!emptyEl) return;
4774
- const fileBtns = this._orderedFileNames().map(f => {
4775
- const ext = f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
4776
- return `
4777
- <button type="button" class="codelab-empty-file-btn" data-cl-file="${escapeHtml(f)}" title="Open ${escapeHtml(f)}">
4778
- <span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext.toUpperCase()}</span>
4779
- <span>${escapeHtml(f)}</span>
4780
- </button>
4781
- `;
4782
- }).join('');
4783
-
4784
4790
  emptyEl.innerHTML = `
4785
4791
  <div class="codelab-empty-editor__inner">
4786
- <div class="codelab-empty-editor__icon" aria-hidden="true">
4787
- <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
4788
- <path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/>
4789
- <polyline points="14 2 14 8 20 8"/>
4790
- </svg>
4791
- </div>
4792
- <h2 class="codelab-empty-editor__title">No Open Editors</h2>
4793
- <p class="codelab-empty-editor__subtitle">Select a file from the explorer on the left or click a workspace file below to open.</p>
4794
- <div class="codelab-empty-editor__files" role="group" aria-label="Workspace Files">
4795
- ${fileBtns}
4796
- </div>
4797
- <div class="codelab-empty-editor__actions">
4798
- <button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⇧⌘↵)">
4799
- ${CL_ICONS.play}
4800
- <span>Run Demo</span>
4801
- <span class="codelab-btn__kbd">⇧⌘↵</span>
4792
+ <div class="codelab-empty-editor__watermark" aria-hidden="true">code-lab</div>
4793
+ <div class="codelab-empty-editor__shortcuts" role="group" aria-label="Quick actions">
4794
+ <button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette-files">
4795
+ <span>Go to File</span><kbd>⌘P</kbd>
4802
4796
  </button>
4803
- <button type="button" class="codelab-btn codelab-btn--test" data-cl-action="run-tests" title="Run Test Suite (⌘↵)">
4804
- ${CL_ICONS.check}
4805
- <span>Run Tests</span>
4806
- <span class="codelab-btn__kbd">⌘↵</span>
4797
+ <button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette">
4798
+ <span>Show All Commands</span><kbd>⌘⇧P</kbd>
4807
4799
  </button>
4808
4800
  </div>
4801
+ <p class="codelab-empty-editor__subtitle">No editors open. Select a file from the Explorer to start editing.</p>
4809
4802
  </div>
4810
4803
  `;
4811
4804
  }
@@ -4875,7 +4868,7 @@ declare module 'bun:sqlite' {
4875
4868
  this.openCommandPalette('files');
4876
4869
  return;
4877
4870
  }
4878
- if ((e.metaKey || e.ctrlKey) && keyLower === 'c') {
4871
+ if (e.ctrlKey && !e.metaKey && keyLower === 'c') {
4879
4872
  const hasSelection = typeof window !== 'undefined' && window.getSelection && window.getSelection().toString().length > 0;
4880
4873
  if (!hasSelection && (this.isRunning || this._activeCommandAbortController)) {
4881
4874
  e.preventDefault();
@@ -5177,6 +5170,7 @@ declare module 'bun:sqlite' {
5177
5170
  if (action === 'run-demo') this.runDemo();
5178
5171
  else if (action === 'run-tests') this.runTests();
5179
5172
  else if (action === 'stop-run') this.stopExecution();
5173
+ else if (action === 'interrupt') this._handleInterrupt();
5180
5174
  else if (action === 'verify-step') this.verifyCurrentStep();
5181
5175
  else if (action === 'show-diff') this.showSolutionModal();
5182
5176
  else if (action === 'compare-diff') {
@@ -5770,6 +5764,48 @@ declare module 'bun:sqlite' {
5770
5764
  hSplitter.addEventListener('pointerup', onUp);
5771
5765
  });
5772
5766
  }
5767
+
5768
+ const fSplitter = this.container.querySelector('#cl-splitter-files');
5769
+ if (fSplitter) {
5770
+ const applyWidth = (w) => {
5771
+ this.explorerWidth = Math.round(w);
5772
+ shell.style.setProperty('--cl-explorer-width', `${this.explorerWidth}px`);
5773
+ if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
5774
+ };
5775
+
5776
+ fSplitter.addEventListener('dblclick', () => {
5777
+ applyWidth(196);
5778
+ this._saveState();
5779
+ });
5780
+
5781
+ fSplitter.addEventListener('pointerdown', e => {
5782
+ e.preventDefault();
5783
+ fSplitter.classList.add('is-dragging');
5784
+ shell.classList.add('is-resizing');
5785
+ try { fSplitter.setPointerCapture(e.pointerId); } catch (_) {}
5786
+
5787
+ const onMove = ev => {
5788
+ const ws = this.container.querySelector('.codelab-workspace');
5789
+ const rect = (ws || shell).getBoundingClientRect();
5790
+ const minW = 140;
5791
+ const maxW = Math.max(minW, Math.floor(rect.width * 0.5));
5792
+ const nextW = Math.min(maxW, Math.max(minW, Math.round(ev.clientX - rect.left)));
5793
+ applyWidth(nextW);
5794
+ };
5795
+
5796
+ const onUp = ev => {
5797
+ fSplitter.classList.remove('is-dragging');
5798
+ shell.classList.remove('is-resizing');
5799
+ try { fSplitter.releasePointerCapture(ev.pointerId); } catch (_) {}
5800
+ fSplitter.removeEventListener('pointermove', onMove);
5801
+ fSplitter.removeEventListener('pointerup', onUp);
5802
+ this._saveState();
5803
+ };
5804
+
5805
+ fSplitter.addEventListener('pointermove', onMove);
5806
+ fSplitter.addEventListener('pointerup', onUp);
5807
+ });
5808
+ }
5773
5809
  }
5774
5810
 
5775
5811
  selectStep(idx, shouldJump = true) {
@@ -6049,14 +6085,14 @@ declare module 'bun:sqlite' {
6049
6085
  </div>
6050
6086
  ${pkgs.length === 0 ? `
6051
6087
  <div style="padding:12px;border:1px solid var(--cl-border);border-radius:var(--cl-radius-sm);background:var(--cl-bg);color:var(--cl-fg-muted);font-size:12.5px;">
6052
- No external npm packages imported yet. Any <code>import ... from 'pkg'</code> or <code>require('pkg')</code> in your code is automatically resolved via <strong>esm.sh</strong> when you run or test.
6088
+ No external npm packages imported yet. Any <code>import ... from 'pkg'</code> or <code>require('pkg')</code> in your code is automatically resolved via <strong>jsDelivr</strong> when you run or test.
6053
6089
  </div>
6054
6090
  ` : `
6055
6091
  <div style="display:flex;flex-direction:column;gap:6px;">
6056
6092
  ${pkgs.map(p => `
6057
6093
  <div style="display:flex;align-items:center;justify-content:space-between;padding:8px 12px;border:1px solid var(--cl-border);border-radius:var(--cl-radius-sm);background:var(--cl-bg);font-family:var(--cl-font-mono);font-size:12px;">
6058
6094
  <span style="color:var(--cl-fg);font-weight:600;">${escapeHtml(p.name)}</span>
6059
- <span style="color:var(--cl-accent);">${escapeHtml(p.version)} · esm.sh</span>
6095
+ <span style="color:var(--cl-accent);">${escapeHtml(p.version)} · jsDelivr</span>
6060
6096
  </div>
6061
6097
  `).join('')}
6062
6098
  </div>
@@ -6166,6 +6202,12 @@ declare module 'bun:sqlite' {
6166
6202
  }
6167
6203
 
6168
6204
  // ── Execution Engine (Web Worker + Virtual Node Runtime) ───────────────
6205
+ _isAbortResult(res, signal) {
6206
+ if (signal && signal.aborted) return true;
6207
+ if (!res || typeof res !== 'object') return false;
6208
+ return Boolean(res.cancelled || res.aborted || res.exitCode === 130);
6209
+ }
6210
+
6169
6211
  async _executeRuntime(execOptions) {
6170
6212
  const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
6171
6213
  const payload = {
@@ -6184,9 +6226,14 @@ declare module 'bun:sqlite' {
6184
6226
  if (detectedList.length > 0) {
6185
6227
  this._setRuntimeStatus('fetching', `Fetching ${detectedList.map(d => typeof d === 'string' ? d : d.name).join(', ')}...`);
6186
6228
  }
6187
- await root.CodeLabRuntime.preloadNpmPackages(payload.files, pkgName => {
6188
- this._setRuntimeStatus('fetching', `Fetching ${pkgName} from esm.sh...`);
6229
+ const preloaded = await root.CodeLabRuntime.preloadNpmPackages(payload.files, pkgName => {
6230
+ this._setRuntimeStatus('fetching', `Fetching ${pkgName} from jsDelivr CDN...`);
6189
6231
  });
6232
+ // Hand the fetched module sources to the runtime so the Web Worker
6233
+ // (which has an isolated module cache) can resolve them from node_modules.
6234
+ if (preloaded && typeof preloaded === 'object' && Object.keys(preloaded).length > 0) {
6235
+ payload.packages = Object.assign({}, preloaded, payload.packages || {});
6236
+ }
6190
6237
  }
6191
6238
  this._setRuntimeStatus('running', `Running ${payload.entry || payload.mode || 'script'}...`);
6192
6239
  let res;
@@ -6202,7 +6249,11 @@ declare module 'bun:sqlite' {
6202
6249
  this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
6203
6250
  return res;
6204
6251
  } catch (err) {
6205
- this._setRuntimeStatus('error', 'Execution error');
6252
+ if (payload.signal && payload.signal.aborted) {
6253
+ this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
6254
+ } else {
6255
+ this._setRuntimeStatus('error', 'Execution error');
6256
+ }
6206
6257
  throw err;
6207
6258
  }
6208
6259
  }
@@ -6244,18 +6295,21 @@ declare module 'bun:sqlite' {
6244
6295
  }
6245
6296
  });
6246
6297
  this._flushTerminalStream();
6298
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
6247
6299
 
6248
- if (!streamedStdout && res.stdout) {
6300
+ if (!aborted && !streamedStdout && res.stdout) {
6249
6301
  this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
6250
6302
  }
6251
- if (!streamedStderr && res.stderr) {
6303
+ if (!aborted && !streamedStderr && res.stderr) {
6252
6304
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
6253
6305
  }
6254
- if (res.error) {
6306
+ if (!aborted && res.error) {
6255
6307
  this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
6256
6308
  }
6257
- this.lastFsSnapshot = res.fsSnapshot || [];
6258
- this.lastHttpTrace = res.httpTrace || [];
6309
+ if (!aborted) {
6310
+ this.lastFsSnapshot = res.fsSnapshot || [];
6311
+ this.lastHttpTrace = res.httpTrace || [];
6312
+ }
6259
6313
 
6260
6314
  if (this.onRun) {
6261
6315
  try { this.onRun(res); } catch (_) {}
@@ -6263,7 +6317,9 @@ declare module 'bun:sqlite' {
6263
6317
  this._emitEvent('codelab:run', { labId: this.labId, mode: 'run', entry, result: res });
6264
6318
  } catch (err) {
6265
6319
  this._flushTerminalStream();
6266
- this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
6320
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
6321
+ this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
6322
+ }
6267
6323
  } finally {
6268
6324
  if (this._activeCommandAbortController === abortCtrl) {
6269
6325
  this._activeCommandAbortController = null;
@@ -6312,18 +6368,21 @@ declare module 'bun:sqlite' {
6312
6368
  }
6313
6369
  });
6314
6370
  this._flushTerminalStream();
6371
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
6315
6372
 
6316
- this.lastTestResults = res.testResults || [];
6317
- this.lastFsSnapshot = res.fsSnapshot || [];
6318
- this.lastHttpTrace = res.httpTrace || [];
6373
+ if (!aborted) {
6374
+ this.lastTestResults = res.testResults || [];
6375
+ this.lastFsSnapshot = res.fsSnapshot || [];
6376
+ this.lastHttpTrace = res.httpTrace || [];
6377
+ }
6319
6378
 
6320
- if (!streamedStdout && res.stdout) {
6379
+ if (!aborted && !streamedStdout && res.stdout) {
6321
6380
  this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
6322
6381
  }
6323
- if (!streamedStderr && res.stderr) {
6382
+ if (!aborted && !streamedStderr && res.stderr) {
6324
6383
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
6325
6384
  }
6326
- if (res.error) {
6385
+ if (!aborted && res.error) {
6327
6386
  this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
6328
6387
  }
6329
6388
 
@@ -6374,7 +6433,9 @@ declare module 'bun:sqlite' {
6374
6433
  }
6375
6434
  } catch (err) {
6376
6435
  this._flushTerminalStream();
6377
- this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
6436
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
6437
+ this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
6438
+ }
6378
6439
  } finally {
6379
6440
  if (this._activeCommandAbortController === abortCtrl) {
6380
6441
  this._activeCommandAbortController = null;
@@ -6465,16 +6526,19 @@ declare module 'bun:sqlite' {
6465
6526
  onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
6466
6527
  });
6467
6528
  this._flushTerminalStream();
6529
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
6468
6530
  const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
6469
- if (!streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
6470
- if (!streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
6471
- if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
6531
+ if (!aborted && !streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
6532
+ if (!aborted && !streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
6533
+ if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
6472
6534
  this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
6473
6535
  }
6474
- if (res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
6536
+ if (!aborted && res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
6475
6537
  } catch (err) {
6476
6538
  this._flushTerminalStream();
6477
- this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6539
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
6540
+ this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6541
+ }
6478
6542
  } finally {
6479
6543
  if (this._activeCommandAbortController === abortCtrl) {
6480
6544
  this._activeCommandAbortController = null;
@@ -6506,8 +6570,17 @@ declare module 'bun:sqlite' {
6506
6570
  return;
6507
6571
  }
6508
6572
 
6509
- const looksLikeJsExpr = /^(const|let|var|function|class|await|return|typeof|instanceof|new\s+|Math\.|JSON\.|Object\.|Array\.|Promise\.|console\.|process\.|Buffer\.|require\s*\(|import\s*\(|[0-9]+\s*[\+\-\*\/\%]|['"`\[{])/.test(trimmed)
6510
- || /^[a-zA-Z_$][\w$]*\s*(\.|===|!==|==|!=|<=|>=|\+=|-=|\*=|\(|\+\+|--)/.test(trimmed);
6573
+ const firstWord = (trimmed.split(/\s+/)[0] || '').replace(/^.*\//, '');
6574
+ const shellKnowsCommand = Boolean(
6575
+ firstWord &&
6576
+ this.shell &&
6577
+ typeof this.shell.hasCommand === 'function' &&
6578
+ this.shell.hasCommand(firstWord)
6579
+ );
6580
+ const looksLikeJsExpr = !shellKnowsCommand && (
6581
+ /^(const|let|var|function|class|await|return|typeof|instanceof|new\s+|Math\.|JSON\.|Object\.|Array\.|Promise\.|console\.|process\.|Buffer\.|require\s*\(|import\s*\(|[0-9]+\s*[\+\-\*\/\%]|['"`\[{])/.test(trimmed)
6582
+ || /^[a-zA-Z_$][\w$]*\s*(\.|===|!==|==|!=|<=|>=|\+=|-=|\*=|\(|\+\+|--)/.test(trimmed)
6583
+ );
6511
6584
 
6512
6585
  if (this.shell && typeof this.shell.execute === 'function' && !looksLikeJsExpr) {
6513
6586
  const abortCtrl = new AbortController();
@@ -6533,6 +6606,7 @@ declare module 'bun:sqlite' {
6533
6606
  signal: abortCtrl.signal
6534
6607
  });
6535
6608
  this._flushTerminalStream();
6609
+ const aborted = this._isAbortResult(shellRes, abortCtrl.signal);
6536
6610
  this.cwd = this.shell.cwd || this.cwd;
6537
6611
  this._syncVfsSnapshot(null, true);
6538
6612
 
@@ -6552,10 +6626,10 @@ declare module 'bun:sqlite' {
6552
6626
 
6553
6627
  const isCmdNotFound = shellRes && shellRes.exitCode === 127 && typeof shellRes.stderr === 'string' && shellRes.stderr.includes('command not found');
6554
6628
  if (!isCmdNotFound) {
6555
- if (shellRes && shellRes.stdout && !streamedStdout) {
6629
+ if (!aborted && shellRes && shellRes.stdout && !streamedStdout) {
6556
6630
  this.terminalLogs.push({ type: 'stdout', text: shellRes.stdout.replace(/\n$/, '') });
6557
6631
  }
6558
- if (shellRes && shellRes.stderr && !streamedStderr) {
6632
+ if (!aborted && shellRes && shellRes.stderr && !streamedStderr) {
6559
6633
  this.terminalLogs.push({ type: 'stderr', text: shellRes.stderr.replace(/\n$/, '') });
6560
6634
  }
6561
6635
  this._renderDrawerBody();
@@ -6568,7 +6642,9 @@ declare module 'bun:sqlite' {
6568
6642
  }
6569
6643
  } catch (err) {
6570
6644
  this._flushTerminalStream();
6571
- this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6645
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
6646
+ this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6647
+ }
6572
6648
  this._renderDrawerBody();
6573
6649
  return;
6574
6650
  } finally {
@@ -6604,17 +6680,18 @@ declare module 'bun:sqlite' {
6604
6680
  }
6605
6681
  });
6606
6682
  this._flushTerminalStream();
6683
+ const aborted = this._isAbortResult(res, fallbackAbortCtrl.signal);
6607
6684
  const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
6608
- if (!streamedFallbackStdout && cleanStdout) {
6685
+ if (!aborted && !streamedFallbackStdout && cleanStdout) {
6609
6686
  this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
6610
6687
  }
6611
- if (!streamedFallbackStderr && res.stderr) {
6688
+ if (!aborted && !streamedFallbackStderr && res.stderr) {
6612
6689
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
6613
6690
  }
6614
- if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
6691
+ if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
6615
6692
  this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
6616
6693
  }
6617
- if (res.error) {
6694
+ if (!aborted && res.error) {
6618
6695
  const errStr = formatErrorText(res.error);
6619
6696
  if (/^[a-zA-Z0-9_-]+$/.test(trimmed) && errStr.includes(`ReferenceError: ${trimmed} is not defined`)) {
6620
6697
  this.terminalLogs.push({ type: 'stderr', text: `codelab: ${trimmed}: command not found (type "help" for commands or enter a JS/TS expression)` });
@@ -6624,7 +6701,9 @@ declare module 'bun:sqlite' {
6624
6701
  }
6625
6702
  } catch (err) {
6626
6703
  this._flushTerminalStream();
6627
- this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6704
+ if (!(fallbackAbortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
6705
+ this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6706
+ }
6628
6707
  } finally {
6629
6708
  if (this._activeCommandAbortController === fallbackAbortCtrl) {
6630
6709
  this._activeCommandAbortController = null;
@@ -6876,8 +6955,13 @@ declare module 'bun:sqlite' {
6876
6955
  const intoRoot = options.intoRoot !== false;
6877
6956
  const targetDir = intoRoot ? '/workspace' : `/workspace/${parsed.repo}`;
6878
6957
  const cmdDisplay = `git clone ${repoInput}${intoRoot ? ' .' : ''}`;
6958
+ this.drawerTab = 'terminal';
6879
6959
  this.terminalLogs.push({ type: 'cmd', text: cmdDisplay });
6960
+ this.isRunning = true;
6961
+ const abortCtrl = new AbortController();
6962
+ this._activeCommandAbortController = abortCtrl;
6880
6963
  this._renderDrawerBody();
6964
+ this._updateRunStateUI();
6881
6965
 
6882
6966
  try {
6883
6967
  if (intoRoot && this.shell && this.shell.vfs) {
@@ -6900,6 +6984,7 @@ declare module 'bun:sqlite' {
6900
6984
  maxFiles: options.maxFiles || 250,
6901
6985
  maxFileSize: options.maxFileSize || 512 * 1024,
6902
6986
  fetchImpl: options.fetchImpl || (this.shell && this.shell.options ? this.shell.options.fetchImpl : undefined),
6987
+ signal: abortCtrl.signal,
6903
6988
  onProgress: options.onProgress
6904
6989
  });
6905
6990
 
@@ -6971,10 +7056,18 @@ declare module 'bun:sqlite' {
6971
7056
  this._emitEvent('repo:cloned', eventDetail);
6972
7057
  return result;
6973
7058
  } catch (err) {
6974
- const msg = err && err.message ? err.message : String(err);
6975
- this.terminalLogs.push({ type: 'stderr', text: msg });
7059
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
7060
+ const msg = err && err.message ? err.message : String(err);
7061
+ this.terminalLogs.push({ type: 'stderr', text: msg });
7062
+ }
6976
7063
  this._renderDrawerBody();
6977
7064
  throw err;
7065
+ } finally {
7066
+ if (this._activeCommandAbortController === abortCtrl) {
7067
+ this._activeCommandAbortController = null;
7068
+ }
7069
+ this.isRunning = false;
7070
+ this._updateRunStateUI();
6978
7071
  }
6979
7072
  }
6980
7073