@innovatorved/code-lab 0.1.2 → 0.1.3

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/dist/code-lab.js CHANGED
@@ -9502,6 +9502,16 @@ if (typeof module !== 'undefined' && module.exports) {
9502
9502
  const requestedBranch = options.branch || parsed.branch || null;
9503
9503
  const { owner, repo } = parsed;
9504
9504
 
9505
+ const signal = options.signal || null;
9506
+ const throwIfAborted = () => {
9507
+ if (signal && signal.aborted) {
9508
+ const abortErr = new Error('fatal: clone cancelled (SIGINT)');
9509
+ abortErr.name = 'AbortError';
9510
+ throw abortErr;
9511
+ }
9512
+ };
9513
+ throwIfAborted();
9514
+
9505
9515
  let resolvedBranch = requestedBranch;
9506
9516
  let rawTreeEntries = null;
9507
9517
  let repoNotFound = false;
@@ -9514,7 +9524,8 @@ if (typeof module !== 'undefined' && module.exports) {
9514
9524
  try {
9515
9525
  if (!resolvedBranch) {
9516
9526
  const metaRes = await fetchFn(`https://api.github.com/repos/${owner}/${repo}`, {
9517
- headers: { Accept: 'application/vnd.github.v3+json' }
9527
+ headers: { Accept: 'application/vnd.github.v3+json' },
9528
+ signal
9518
9529
  });
9519
9530
  if (metaRes.status === 404) {
9520
9531
  repoNotFound = true;
@@ -9532,9 +9543,10 @@ if (typeof module !== 'undefined' && module.exports) {
9532
9543
  : Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
9533
9544
 
9534
9545
  for (const cand of branchCandidates) {
9546
+ throwIfAborted();
9535
9547
  const treeRes = await fetchFn(
9536
9548
  `https://api.github.com/repos/${owner}/${repo}/git/trees/${encodeURIComponent(cand)}?recursive=1`,
9537
- { headers: { Accept: 'application/vnd.github.v3+json' } }
9549
+ { headers: { Accept: 'application/vnd.github.v3+json' }, signal }
9538
9550
  );
9539
9551
  if (treeRes.ok) {
9540
9552
  const treeJson = await treeRes.json();
@@ -9560,8 +9572,10 @@ if (typeof module !== 'undefined' && module.exports) {
9560
9572
  : Array.from(new Set([resolvedBranch, 'main', 'master'].filter(Boolean)));
9561
9573
 
9562
9574
  for (const cand of branchCandidates) {
9575
+ throwIfAborted();
9563
9576
  const flatRes = await fetchFn(
9564
- `https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat`
9577
+ `https://data.jsdelivr.com/v1/package/gh/${owner}/${repo}@${encodeURIComponent(cand)}/flat`,
9578
+ { signal }
9565
9579
  );
9566
9580
  if (flatRes && flatRes.ok) {
9567
9581
  const flatJson = await flatRes.json();
@@ -9630,28 +9644,34 @@ if (typeof module !== 'undefined' && module.exports) {
9630
9644
  const BATCH_SIZE = 12;
9631
9645
 
9632
9646
  for (let i = 0; i < selectedFiles.length; i += BATCH_SIZE) {
9647
+ throwIfAborted();
9633
9648
  const batch = selectedFiles.slice(i, i + BATCH_SIZE);
9634
9649
  await Promise.all(
9635
9650
  batch.map(async (entry) => {
9651
+ throwIfAborted();
9636
9652
  const encodedPath = entry.repoPath.split('/').map(encodeURIComponent).join('/');
9637
9653
  const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
9638
9654
  const cdnUrl = `https://cdn.jsdelivr.net/gh/${owner}/${repo}@${encodeURIComponent(resolvedBranch)}/${encodedPath}`;
9639
9655
 
9640
9656
  let text = null;
9641
9657
  try {
9642
- const r1 = await fetchFn(rawUrl);
9658
+ const r1 = await fetchFn(rawUrl, { signal });
9643
9659
  if (r1 && r1.ok) {
9644
9660
  text = await r1.text();
9645
9661
  }
9646
- } catch (_) {}
9662
+ } catch (_) {
9663
+ if (signal && signal.aborted) throw _;
9664
+ }
9647
9665
 
9648
9666
  if (text === null) {
9649
9667
  try {
9650
- const r2 = await fetchFn(cdnUrl);
9668
+ const r2 = await fetchFn(cdnUrl, { signal });
9651
9669
  if (r2 && r2.ok) {
9652
9670
  text = await r2.text();
9653
9671
  }
9654
- } catch (_) {}
9672
+ } catch (_) {
9673
+ if (signal && signal.aborted) throw _;
9674
+ }
9655
9675
  }
9656
9676
 
9657
9677
  if (text !== null && text.length <= maxFileSize) {
@@ -9675,6 +9695,8 @@ if (typeof module !== 'undefined' && module.exports) {
9675
9695
  );
9676
9696
  }
9677
9697
 
9698
+ throwIfAborted();
9699
+
9678
9700
  if (onProgress) {
9679
9701
  onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
9680
9702
  }
@@ -9695,7 +9717,7 @@ if (typeof module !== 'undefined' && module.exports) {
9695
9717
  try {
9696
9718
  const commitsRes = await fetchFn(
9697
9719
  `https://api.github.com/repos/${owner}/${repo}/commits?sha=${encodeURIComponent(resolvedBranch)}&per_page=10`,
9698
- { headers: { Accept: 'application/vnd.github.v3+json' } }
9720
+ { headers: { Accept: 'application/vnd.github.v3+json' }, signal }
9699
9721
  );
9700
9722
  if (commitsRes && commitsRes.ok) {
9701
9723
  const commitsJson = await commitsRes.json();
@@ -11942,6 +11964,7 @@ if (typeof module !== 'undefined' && module.exports) {
11942
11964
  targetDir,
11943
11965
  branch: branchOpt,
11944
11966
  fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
11967
+ signal: ctx.signal,
11945
11968
  onFile: (absPath) => ctx.emitMutation('create', absPath),
11946
11969
  onProgress: (ev) => {
11947
11970
  if (!ev) return;
@@ -11982,6 +12005,9 @@ if (typeof module !== 'undefined' && module.exports) {
11982
12005
  `Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`;
11983
12006
  return { code: 0, stdout, stderr: '' };
11984
12007
  } catch (err) {
12008
+ if (ctx.signal && ctx.signal.aborted) {
12009
+ return { code: 130, stdout: '', stderr: '', aborted: true };
12010
+ }
11985
12011
  const msg = err && err.message ? err.message : String(err);
11986
12012
  if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
11987
12013
  return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
@@ -12309,6 +12335,7 @@ if (typeof module !== 'undefined' && module.exports) {
12309
12335
  targetDir: repoRoot,
12310
12336
  branch: gitState.branch,
12311
12337
  fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
12338
+ signal: ctx.signal,
12312
12339
  onFile: (absPath) => ctx.emitMutation('change', absPath)
12313
12340
  });
12314
12341
  gitState.headSnapshot = Object.assign({}, result.headSnapshot);
@@ -12318,6 +12345,9 @@ if (typeof module !== 'undefined' && module.exports) {
12318
12345
  stderr: ''
12319
12346
  };
12320
12347
  } catch (err) {
12348
+ if (ctx.signal && ctx.signal.aborted) {
12349
+ return { code: 130, stdout: '', stderr: '', aborted: true };
12350
+ }
12321
12351
  const msg = err && err.message ? err.message : String(err);
12322
12352
  return { code: 1, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
12323
12353
  }
@@ -16133,6 +16163,9 @@ declare module 'bun:sqlite' {
16133
16163
  this.folders = new Set(this.savedState?.folders || []);
16134
16164
  this.collapsedFolders = new Set(this.savedState?.collapsedFolders || []);
16135
16165
  this.explorerFolder = this.savedState?.explorerFolder || ''; // '' = workspace root, else folder path scope
16166
+ this.explorerWidth = (typeof this.savedState?.explorerWidth === 'number' && this.savedState.explorerWidth >= 120)
16167
+ ? this.savedState.explorerWidth
16168
+ : 196;
16136
16169
  this.folderSwitcherOpen = false;
16137
16170
  this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
16138
16171
  this.renamingItem = null;
@@ -16470,7 +16503,8 @@ declare module 'bun:sqlite' {
16470
16503
  activeFile: this.activeFile,
16471
16504
  folders: Array.from(this.folders || []),
16472
16505
  collapsedFolders: Array.from(this.collapsedFolders || []),
16473
- explorerFolder: this.explorerFolder || ''
16506
+ explorerFolder: this.explorerFolder || '',
16507
+ explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined
16474
16508
  };
16475
16509
  this.savedState = state;
16476
16510
  if (this.options && this.options.persistState === false) {
@@ -16651,6 +16685,13 @@ declare module 'bun:sqlite' {
16651
16685
  if (stopBtn) {
16652
16686
  stopBtn.style.display = this.isRunning ? 'inline-flex' : 'none';
16653
16687
  }
16688
+ const ctrlCBtn = this.container.querySelector('#cl-ctrl-c-btn');
16689
+ if (ctrlCBtn) {
16690
+ ctrlCBtn.classList.toggle('is-running', Boolean(this.isRunning));
16691
+ ctrlCBtn.title = this.isRunning
16692
+ ? 'Send Ctrl+C — interrupt the running command'
16693
+ : 'Send Ctrl+C (clears the current input line)';
16694
+ }
16654
16695
  this.container.querySelectorAll('[data-cl-action="run-demo"], [data-cl-action="run-tests"], [data-cl-action="verify-step"]').forEach(btn => {
16655
16696
  btn.disabled = this.isRunning;
16656
16697
  });
@@ -16665,8 +16706,9 @@ declare module 'bun:sqlite' {
16665
16706
  const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
16666
16707
  const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
16667
16708
  const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
16709
+ const explorerStyle = `style="--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px"`;
16668
16710
  this.container.innerHTML = `
16669
- <div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr}>
16711
+ <div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
16670
16712
  <!-- Top Bar -->
16671
16713
  <div class="codelab-topbar codelab-toolbar">
16672
16714
  <div class="codelab-topbar__left">
@@ -16782,6 +16824,9 @@ declare module 'bun:sqlite' {
16782
16824
  <div class="codelab-explorer__list" id="cl-explorer-list"></div>
16783
16825
  </div>
16784
16826
 
16827
+ <!-- Explorer Resize Splitter -->
16828
+ <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>
16829
+
16785
16830
  <!-- Editor Column -->
16786
16831
  <div class="codelab-editor-col">
16787
16832
  <div class="codelab-tabs codelab-file-tabs" id="cl-file-tabs" role="tablist" aria-label="Open Files"></div>
@@ -16835,6 +16880,7 @@ declare module 'bun:sqlite' {
16835
16880
  </button>
16836
16881
  </div>
16837
16882
  <div style="display:flex;align-items:center;gap:6px;">
16883
+ <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>
16838
16884
  <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>
16839
16885
  <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>
16840
16886
  </div>
@@ -17976,10 +18022,10 @@ declare module 'bun:sqlite' {
17976
18022
  this._ptyInputAfterCursor = '';
17977
18023
  this._updatePtyActiveLine();
17978
18024
  }
17979
- } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c') {
18025
+ } else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'c') {
17980
18026
  e.preventDefault();
17981
18027
  this._handleInterrupt();
17982
- } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'd') {
18028
+ } else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'd') {
17983
18029
  e.preventDefault();
17984
18030
  if (this.inRepl) {
17985
18031
  this.inRepl = false;
@@ -17988,7 +18034,7 @@ declare module 'bun:sqlite' {
17988
18034
  const nextInput = this.container.querySelector('#cl-repl-input');
17989
18035
  if (nextInput && typeof nextInput.focus === 'function') nextInput.focus();
17990
18036
  }
17991
- } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'l') {
18037
+ } else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'l') {
17992
18038
  e.preventDefault();
17993
18039
  this.terminalLogs = [];
17994
18040
  this._renderDrawerBody();
@@ -19733,41 +19779,18 @@ declare module 'bun:sqlite' {
19733
19779
 
19734
19780
  _renderEmptyEditorContent(emptyEl) {
19735
19781
  if (!emptyEl) return;
19736
- const fileBtns = this._orderedFileNames().map(f => {
19737
- const ext = f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
19738
- return `
19739
- <button type="button" class="codelab-empty-file-btn" data-cl-file="${escapeHtml(f)}" title="Open ${escapeHtml(f)}">
19740
- <span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext.toUpperCase()}</span>
19741
- <span>${escapeHtml(f)}</span>
19742
- </button>
19743
- `;
19744
- }).join('');
19745
-
19746
19782
  emptyEl.innerHTML = `
19747
19783
  <div class="codelab-empty-editor__inner">
19748
- <div class="codelab-empty-editor__icon" aria-hidden="true">
19749
- <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
19750
- <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"/>
19751
- <polyline points="14 2 14 8 20 8"/>
19752
- </svg>
19753
- </div>
19754
- <h2 class="codelab-empty-editor__title">No Open Editors</h2>
19755
- <p class="codelab-empty-editor__subtitle">Select a file from the explorer on the left or click a workspace file below to open.</p>
19756
- <div class="codelab-empty-editor__files" role="group" aria-label="Workspace Files">
19757
- ${fileBtns}
19758
- </div>
19759
- <div class="codelab-empty-editor__actions">
19760
- <button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⇧⌘↵)">
19761
- ${CL_ICONS.play}
19762
- <span>Run Demo</span>
19763
- <span class="codelab-btn__kbd">⇧⌘↵</span>
19784
+ <div class="codelab-empty-editor__watermark" aria-hidden="true">code-lab</div>
19785
+ <div class="codelab-empty-editor__shortcuts" role="group" aria-label="Quick actions">
19786
+ <button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette-files">
19787
+ <span>Go to File</span><kbd>⌘P</kbd>
19764
19788
  </button>
19765
- <button type="button" class="codelab-btn codelab-btn--test" data-cl-action="run-tests" title="Run Test Suite (⌘↵)">
19766
- ${CL_ICONS.check}
19767
- <span>Run Tests</span>
19768
- <span class="codelab-btn__kbd">⌘↵</span>
19789
+ <button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette">
19790
+ <span>Show All Commands</span><kbd>⌘⇧P</kbd>
19769
19791
  </button>
19770
19792
  </div>
19793
+ <p class="codelab-empty-editor__subtitle">No editors open. Select a file from the Explorer to start editing.</p>
19771
19794
  </div>
19772
19795
  `;
19773
19796
  }
@@ -19837,7 +19860,7 @@ declare module 'bun:sqlite' {
19837
19860
  this.openCommandPalette('files');
19838
19861
  return;
19839
19862
  }
19840
- if ((e.metaKey || e.ctrlKey) && keyLower === 'c') {
19863
+ if (e.ctrlKey && !e.metaKey && keyLower === 'c') {
19841
19864
  const hasSelection = typeof window !== 'undefined' && window.getSelection && window.getSelection().toString().length > 0;
19842
19865
  if (!hasSelection && (this.isRunning || this._activeCommandAbortController)) {
19843
19866
  e.preventDefault();
@@ -20139,6 +20162,7 @@ declare module 'bun:sqlite' {
20139
20162
  if (action === 'run-demo') this.runDemo();
20140
20163
  else if (action === 'run-tests') this.runTests();
20141
20164
  else if (action === 'stop-run') this.stopExecution();
20165
+ else if (action === 'interrupt') this._handleInterrupt();
20142
20166
  else if (action === 'verify-step') this.verifyCurrentStep();
20143
20167
  else if (action === 'show-diff') this.showSolutionModal();
20144
20168
  else if (action === 'compare-diff') {
@@ -20732,6 +20756,48 @@ declare module 'bun:sqlite' {
20732
20756
  hSplitter.addEventListener('pointerup', onUp);
20733
20757
  });
20734
20758
  }
20759
+
20760
+ const fSplitter = this.container.querySelector('#cl-splitter-files');
20761
+ if (fSplitter) {
20762
+ const applyWidth = (w) => {
20763
+ this.explorerWidth = Math.round(w);
20764
+ shell.style.setProperty('--cl-explorer-width', `${this.explorerWidth}px`);
20765
+ if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
20766
+ };
20767
+
20768
+ fSplitter.addEventListener('dblclick', () => {
20769
+ applyWidth(196);
20770
+ this._saveState();
20771
+ });
20772
+
20773
+ fSplitter.addEventListener('pointerdown', e => {
20774
+ e.preventDefault();
20775
+ fSplitter.classList.add('is-dragging');
20776
+ shell.classList.add('is-resizing');
20777
+ try { fSplitter.setPointerCapture(e.pointerId); } catch (_) {}
20778
+
20779
+ const onMove = ev => {
20780
+ const ws = this.container.querySelector('.codelab-workspace');
20781
+ const rect = (ws || shell).getBoundingClientRect();
20782
+ const minW = 140;
20783
+ const maxW = Math.max(minW, Math.floor(rect.width * 0.5));
20784
+ const nextW = Math.min(maxW, Math.max(minW, Math.round(ev.clientX - rect.left)));
20785
+ applyWidth(nextW);
20786
+ };
20787
+
20788
+ const onUp = ev => {
20789
+ fSplitter.classList.remove('is-dragging');
20790
+ shell.classList.remove('is-resizing');
20791
+ try { fSplitter.releasePointerCapture(ev.pointerId); } catch (_) {}
20792
+ fSplitter.removeEventListener('pointermove', onMove);
20793
+ fSplitter.removeEventListener('pointerup', onUp);
20794
+ this._saveState();
20795
+ };
20796
+
20797
+ fSplitter.addEventListener('pointermove', onMove);
20798
+ fSplitter.addEventListener('pointerup', onUp);
20799
+ });
20800
+ }
20735
20801
  }
20736
20802
 
20737
20803
  selectStep(idx, shouldJump = true) {
@@ -21128,6 +21194,12 @@ declare module 'bun:sqlite' {
21128
21194
  }
21129
21195
 
21130
21196
  // ── Execution Engine (Web Worker + Virtual Node Runtime) ───────────────
21197
+ _isAbortResult(res, signal) {
21198
+ if (signal && signal.aborted) return true;
21199
+ if (!res || typeof res !== 'object') return false;
21200
+ return Boolean(res.cancelled || res.aborted || res.exitCode === 130);
21201
+ }
21202
+
21131
21203
  async _executeRuntime(execOptions) {
21132
21204
  const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
21133
21205
  const payload = {
@@ -21164,7 +21236,11 @@ declare module 'bun:sqlite' {
21164
21236
  this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
21165
21237
  return res;
21166
21238
  } catch (err) {
21167
- this._setRuntimeStatus('error', 'Execution error');
21239
+ if (payload.signal && payload.signal.aborted) {
21240
+ this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
21241
+ } else {
21242
+ this._setRuntimeStatus('error', 'Execution error');
21243
+ }
21168
21244
  throw err;
21169
21245
  }
21170
21246
  }
@@ -21206,18 +21282,21 @@ declare module 'bun:sqlite' {
21206
21282
  }
21207
21283
  });
21208
21284
  this._flushTerminalStream();
21285
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
21209
21286
 
21210
- if (!streamedStdout && res.stdout) {
21287
+ if (!aborted && !streamedStdout && res.stdout) {
21211
21288
  this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
21212
21289
  }
21213
- if (!streamedStderr && res.stderr) {
21290
+ if (!aborted && !streamedStderr && res.stderr) {
21214
21291
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
21215
21292
  }
21216
- if (res.error) {
21293
+ if (!aborted && res.error) {
21217
21294
  this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
21218
21295
  }
21219
- this.lastFsSnapshot = res.fsSnapshot || [];
21220
- this.lastHttpTrace = res.httpTrace || [];
21296
+ if (!aborted) {
21297
+ this.lastFsSnapshot = res.fsSnapshot || [];
21298
+ this.lastHttpTrace = res.httpTrace || [];
21299
+ }
21221
21300
 
21222
21301
  if (this.onRun) {
21223
21302
  try { this.onRun(res); } catch (_) {}
@@ -21225,7 +21304,9 @@ declare module 'bun:sqlite' {
21225
21304
  this._emitEvent('codelab:run', { labId: this.labId, mode: 'run', entry, result: res });
21226
21305
  } catch (err) {
21227
21306
  this._flushTerminalStream();
21228
- this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
21307
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
21308
+ this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
21309
+ }
21229
21310
  } finally {
21230
21311
  if (this._activeCommandAbortController === abortCtrl) {
21231
21312
  this._activeCommandAbortController = null;
@@ -21274,18 +21355,21 @@ declare module 'bun:sqlite' {
21274
21355
  }
21275
21356
  });
21276
21357
  this._flushTerminalStream();
21358
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
21277
21359
 
21278
- this.lastTestResults = res.testResults || [];
21279
- this.lastFsSnapshot = res.fsSnapshot || [];
21280
- this.lastHttpTrace = res.httpTrace || [];
21360
+ if (!aborted) {
21361
+ this.lastTestResults = res.testResults || [];
21362
+ this.lastFsSnapshot = res.fsSnapshot || [];
21363
+ this.lastHttpTrace = res.httpTrace || [];
21364
+ }
21281
21365
 
21282
- if (!streamedStdout && res.stdout) {
21366
+ if (!aborted && !streamedStdout && res.stdout) {
21283
21367
  this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
21284
21368
  }
21285
- if (!streamedStderr && res.stderr) {
21369
+ if (!aborted && !streamedStderr && res.stderr) {
21286
21370
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
21287
21371
  }
21288
- if (res.error) {
21372
+ if (!aborted && res.error) {
21289
21373
  this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
21290
21374
  }
21291
21375
 
@@ -21336,7 +21420,9 @@ declare module 'bun:sqlite' {
21336
21420
  }
21337
21421
  } catch (err) {
21338
21422
  this._flushTerminalStream();
21339
- this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
21423
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
21424
+ this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
21425
+ }
21340
21426
  } finally {
21341
21427
  if (this._activeCommandAbortController === abortCtrl) {
21342
21428
  this._activeCommandAbortController = null;
@@ -21427,16 +21513,19 @@ declare module 'bun:sqlite' {
21427
21513
  onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
21428
21514
  });
21429
21515
  this._flushTerminalStream();
21516
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
21430
21517
  const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
21431
- if (!streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
21432
- if (!streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
21433
- if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
21518
+ if (!aborted && !streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
21519
+ if (!aborted && !streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
21520
+ if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
21434
21521
  this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
21435
21522
  }
21436
- if (res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
21523
+ if (!aborted && res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
21437
21524
  } catch (err) {
21438
21525
  this._flushTerminalStream();
21439
- this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
21526
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
21527
+ this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
21528
+ }
21440
21529
  } finally {
21441
21530
  if (this._activeCommandAbortController === abortCtrl) {
21442
21531
  this._activeCommandAbortController = null;
@@ -21495,6 +21584,7 @@ declare module 'bun:sqlite' {
21495
21584
  signal: abortCtrl.signal
21496
21585
  });
21497
21586
  this._flushTerminalStream();
21587
+ const aborted = this._isAbortResult(shellRes, abortCtrl.signal);
21498
21588
  this.cwd = this.shell.cwd || this.cwd;
21499
21589
  this._syncVfsSnapshot(null, true);
21500
21590
 
@@ -21514,10 +21604,10 @@ declare module 'bun:sqlite' {
21514
21604
 
21515
21605
  const isCmdNotFound = shellRes && shellRes.exitCode === 127 && typeof shellRes.stderr === 'string' && shellRes.stderr.includes('command not found');
21516
21606
  if (!isCmdNotFound) {
21517
- if (shellRes && shellRes.stdout && !streamedStdout) {
21607
+ if (!aborted && shellRes && shellRes.stdout && !streamedStdout) {
21518
21608
  this.terminalLogs.push({ type: 'stdout', text: shellRes.stdout.replace(/\n$/, '') });
21519
21609
  }
21520
- if (shellRes && shellRes.stderr && !streamedStderr) {
21610
+ if (!aborted && shellRes && shellRes.stderr && !streamedStderr) {
21521
21611
  this.terminalLogs.push({ type: 'stderr', text: shellRes.stderr.replace(/\n$/, '') });
21522
21612
  }
21523
21613
  this._renderDrawerBody();
@@ -21530,7 +21620,9 @@ declare module 'bun:sqlite' {
21530
21620
  }
21531
21621
  } catch (err) {
21532
21622
  this._flushTerminalStream();
21533
- this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
21623
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
21624
+ this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
21625
+ }
21534
21626
  this._renderDrawerBody();
21535
21627
  return;
21536
21628
  } finally {
@@ -21566,17 +21658,18 @@ declare module 'bun:sqlite' {
21566
21658
  }
21567
21659
  });
21568
21660
  this._flushTerminalStream();
21661
+ const aborted = this._isAbortResult(res, fallbackAbortCtrl.signal);
21569
21662
  const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
21570
- if (!streamedFallbackStdout && cleanStdout) {
21663
+ if (!aborted && !streamedFallbackStdout && cleanStdout) {
21571
21664
  this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
21572
21665
  }
21573
- if (!streamedFallbackStderr && res.stderr) {
21666
+ if (!aborted && !streamedFallbackStderr && res.stderr) {
21574
21667
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
21575
21668
  }
21576
- if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
21669
+ if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
21577
21670
  this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
21578
21671
  }
21579
- if (res.error) {
21672
+ if (!aborted && res.error) {
21580
21673
  const errStr = formatErrorText(res.error);
21581
21674
  if (/^[a-zA-Z0-9_-]+$/.test(trimmed) && errStr.includes(`ReferenceError: ${trimmed} is not defined`)) {
21582
21675
  this.terminalLogs.push({ type: 'stderr', text: `codelab: ${trimmed}: command not found (type "help" for commands or enter a JS/TS expression)` });
@@ -21586,7 +21679,9 @@ declare module 'bun:sqlite' {
21586
21679
  }
21587
21680
  } catch (err) {
21588
21681
  this._flushTerminalStream();
21589
- this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
21682
+ if (!(fallbackAbortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
21683
+ this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
21684
+ }
21590
21685
  } finally {
21591
21686
  if (this._activeCommandAbortController === fallbackAbortCtrl) {
21592
21687
  this._activeCommandAbortController = null;
@@ -21838,8 +21933,13 @@ declare module 'bun:sqlite' {
21838
21933
  const intoRoot = options.intoRoot !== false;
21839
21934
  const targetDir = intoRoot ? '/workspace' : `/workspace/${parsed.repo}`;
21840
21935
  const cmdDisplay = `git clone ${repoInput}${intoRoot ? ' .' : ''}`;
21936
+ this.drawerTab = 'terminal';
21841
21937
  this.terminalLogs.push({ type: 'cmd', text: cmdDisplay });
21938
+ this.isRunning = true;
21939
+ const abortCtrl = new AbortController();
21940
+ this._activeCommandAbortController = abortCtrl;
21842
21941
  this._renderDrawerBody();
21942
+ this._updateRunStateUI();
21843
21943
 
21844
21944
  try {
21845
21945
  if (intoRoot && this.shell && this.shell.vfs) {
@@ -21862,6 +21962,7 @@ declare module 'bun:sqlite' {
21862
21962
  maxFiles: options.maxFiles || 250,
21863
21963
  maxFileSize: options.maxFileSize || 512 * 1024,
21864
21964
  fetchImpl: options.fetchImpl || (this.shell && this.shell.options ? this.shell.options.fetchImpl : undefined),
21965
+ signal: abortCtrl.signal,
21865
21966
  onProgress: options.onProgress
21866
21967
  });
21867
21968
 
@@ -21933,10 +22034,18 @@ declare module 'bun:sqlite' {
21933
22034
  this._emitEvent('repo:cloned', eventDetail);
21934
22035
  return result;
21935
22036
  } catch (err) {
21936
- const msg = err && err.message ? err.message : String(err);
21937
- this.terminalLogs.push({ type: 'stderr', text: msg });
22037
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
22038
+ const msg = err && err.message ? err.message : String(err);
22039
+ this.terminalLogs.push({ type: 'stderr', text: msg });
22040
+ }
21938
22041
  this._renderDrawerBody();
21939
22042
  throw err;
22043
+ } finally {
22044
+ if (this._activeCommandAbortController === abortCtrl) {
22045
+ this._activeCommandAbortController = null;
22046
+ }
22047
+ this.isRunning = false;
22048
+ this._updateRunStateUI();
21940
22049
  }
21941
22050
  }
21942
22051