@innovatorved/code-lab 0.1.1 → 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/src/workbench.ts CHANGED
@@ -1172,6 +1172,9 @@ declare module 'bun:sqlite' {
1172
1172
  this.folders = new Set(this.savedState?.folders || []);
1173
1173
  this.collapsedFolders = new Set(this.savedState?.collapsedFolders || []);
1174
1174
  this.explorerFolder = this.savedState?.explorerFolder || ''; // '' = workspace root, else folder path scope
1175
+ this.explorerWidth = (typeof this.savedState?.explorerWidth === 'number' && this.savedState.explorerWidth >= 120)
1176
+ ? this.savedState.explorerWidth
1177
+ : 196;
1175
1178
  this.folderSwitcherOpen = false;
1176
1179
  this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
1177
1180
  this.renamingItem = null;
@@ -1509,7 +1512,8 @@ declare module 'bun:sqlite' {
1509
1512
  activeFile: this.activeFile,
1510
1513
  folders: Array.from(this.folders || []),
1511
1514
  collapsedFolders: Array.from(this.collapsedFolders || []),
1512
- explorerFolder: this.explorerFolder || ''
1515
+ explorerFolder: this.explorerFolder || '',
1516
+ explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined
1513
1517
  };
1514
1518
  this.savedState = state;
1515
1519
  if (this.options && this.options.persistState === false) {
@@ -1690,6 +1694,13 @@ declare module 'bun:sqlite' {
1690
1694
  if (stopBtn) {
1691
1695
  stopBtn.style.display = this.isRunning ? 'inline-flex' : 'none';
1692
1696
  }
1697
+ const ctrlCBtn = this.container.querySelector('#cl-ctrl-c-btn');
1698
+ if (ctrlCBtn) {
1699
+ ctrlCBtn.classList.toggle('is-running', Boolean(this.isRunning));
1700
+ ctrlCBtn.title = this.isRunning
1701
+ ? 'Send Ctrl+C — interrupt the running command'
1702
+ : 'Send Ctrl+C (clears the current input line)';
1703
+ }
1693
1704
  this.container.querySelectorAll('[data-cl-action="run-demo"], [data-cl-action="run-tests"], [data-cl-action="verify-step"]').forEach(btn => {
1694
1705
  btn.disabled = this.isRunning;
1695
1706
  });
@@ -1704,8 +1715,9 @@ declare module 'bun:sqlite' {
1704
1715
  const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
1705
1716
  const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
1706
1717
  const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
1718
+ const explorerStyle = `style="--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px"`;
1707
1719
  this.container.innerHTML = `
1708
- <div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr}>
1720
+ <div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
1709
1721
  <!-- Top Bar -->
1710
1722
  <div class="codelab-topbar codelab-toolbar">
1711
1723
  <div class="codelab-topbar__left">
@@ -1821,6 +1833,9 @@ declare module 'bun:sqlite' {
1821
1833
  <div class="codelab-explorer__list" id="cl-explorer-list"></div>
1822
1834
  </div>
1823
1835
 
1836
+ <!-- Explorer Resize Splitter -->
1837
+ <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>
1838
+
1824
1839
  <!-- Editor Column -->
1825
1840
  <div class="codelab-editor-col">
1826
1841
  <div class="codelab-tabs codelab-file-tabs" id="cl-file-tabs" role="tablist" aria-label="Open Files"></div>
@@ -1874,6 +1889,7 @@ declare module 'bun:sqlite' {
1874
1889
  </button>
1875
1890
  </div>
1876
1891
  <div style="display:flex;align-items:center;gap:6px;">
1892
+ <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>
1877
1893
  <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>
1878
1894
  <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>
1879
1895
  </div>
@@ -3015,10 +3031,10 @@ declare module 'bun:sqlite' {
3015
3031
  this._ptyInputAfterCursor = '';
3016
3032
  this._updatePtyActiveLine();
3017
3033
  }
3018
- } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c') {
3034
+ } else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'c') {
3019
3035
  e.preventDefault();
3020
3036
  this._handleInterrupt();
3021
- } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'd') {
3037
+ } else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'd') {
3022
3038
  e.preventDefault();
3023
3039
  if (this.inRepl) {
3024
3040
  this.inRepl = false;
@@ -3027,7 +3043,7 @@ declare module 'bun:sqlite' {
3027
3043
  const nextInput = this.container.querySelector('#cl-repl-input');
3028
3044
  if (nextInput && typeof nextInput.focus === 'function') nextInput.focus();
3029
3045
  }
3030
- } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'l') {
3046
+ } else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'l') {
3031
3047
  e.preventDefault();
3032
3048
  this.terminalLogs = [];
3033
3049
  this._renderDrawerBody();
@@ -3154,6 +3170,39 @@ declare module 'bun:sqlite' {
3154
3170
  const termSurface = this.container ? this.container.querySelector('#cl-terminal-surface') : null;
3155
3171
  const drawerBody = this.container ? this.container.querySelector('.codelab-drawer__body') : null;
3156
3172
 
3173
+ // The workbench owns live terminal rendering. Only defer when an attached PTY
3174
+ // engine is itself rendering into the DOM (it is created with a null container in
3175
+ // production, so this remains the sole renderer there).
3176
+ const ptyOwnsDom = Boolean(this.ptyEngine && this.ptyEngine.container);
3177
+ const canPatchDom = Boolean(termLogEl && typeof document !== 'undefined' && !ptyOwnsDom);
3178
+
3179
+ // Write a single logical line into the live terminal DOM immediately, so output
3180
+ // streams in as it is produced instead of appearing only when the command ends and
3181
+ // the whole drawer is re-rendered. Reuses the current partial-line element when it
3182
+ // is still attached (carriage-return overwrites / keep-alive updates).
3183
+ const patchLineInDom = (text) => {
3184
+ if (!canPatchDom) return;
3185
+ const html = ansiToHtml ? ansiToHtml(text) : escapeHtml(text);
3186
+ if (this._activeStreamEl && this._activeStreamEl.parentNode === termLogEl) {
3187
+ this._activeStreamEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
3188
+ this._activeStreamEl.innerHTML = html;
3189
+ } else {
3190
+ const newEl = document.createElement('div');
3191
+ newEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
3192
+ newEl.innerHTML = html;
3193
+ termLogEl.appendChild(newEl);
3194
+ this._activeStreamEl = newEl;
3195
+ }
3196
+ };
3197
+
3198
+ // A newline completes the current line: commit it to the log + DOM, then begin a fresh line.
3199
+ const commitActiveLine = () => {
3200
+ this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
3201
+ patchLineInDom(this._activeStreamLine);
3202
+ this._activeStreamLine = '';
3203
+ this._activeStreamEl = null;
3204
+ };
3205
+
3157
3206
  let i = 0;
3158
3207
  while (i < rawText.length) {
3159
3208
  if (rawText.startsWith('\x1b[2K', i)) {
@@ -3188,20 +3237,22 @@ declare module 'bun:sqlite' {
3188
3237
  const ch = rawText[i];
3189
3238
  if (ch === '\r') {
3190
3239
  if (i + 1 < rawText.length && rawText[i + 1] === '\n') {
3191
- this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
3192
- this._activeStreamLine = '';
3193
- this._activeStreamEl = null;
3240
+ commitActiveLine();
3194
3241
  i += 2;
3195
3242
  continue;
3196
3243
  } else {
3244
+ // Bare carriage return: flush the current text into the active line, then
3245
+ // keep overwriting that same DOM node (no extra line is appended).
3246
+ const rendered = this._activeStreamLine;
3247
+ if (rendered || this._activeStreamEl) {
3248
+ patchLineInDom(rendered);
3249
+ }
3197
3250
  this._activeStreamLine = '';
3198
3251
  i++;
3199
3252
  continue;
3200
3253
  }
3201
3254
  } else if (ch === '\n') {
3202
- this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
3203
- this._activeStreamLine = '';
3204
- this._activeStreamEl = null;
3255
+ commitActiveLine();
3205
3256
  i++;
3206
3257
  continue;
3207
3258
  } else {
@@ -3210,20 +3261,9 @@ declare module 'bun:sqlite' {
3210
3261
  }
3211
3262
  }
3212
3263
 
3213
- if (termLogEl && typeof document !== 'undefined') {
3214
- if (this._activeStreamLine) {
3215
- const formattedHtml = ansiToHtml ? ansiToHtml(this._activeStreamLine) : escapeHtml(this._activeStreamLine);
3216
- if (this._activeStreamEl && this._activeStreamEl.parentNode === termLogEl) {
3217
- this._activeStreamEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
3218
- this._activeStreamEl.innerHTML = formattedHtml;
3219
- } else {
3220
- const newEl = document.createElement('div');
3221
- newEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
3222
- newEl.innerHTML = formattedHtml;
3223
- termLogEl.appendChild(newEl);
3224
- this._activeStreamEl = newEl;
3225
- }
3226
- }
3264
+ // Render the still-open partial line so incremental progress stays visible.
3265
+ if (this._activeStreamLine) {
3266
+ patchLineInDom(this._activeStreamLine);
3227
3267
  }
3228
3268
 
3229
3269
  if (termSurface) {
@@ -4748,41 +4788,18 @@ declare module 'bun:sqlite' {
4748
4788
 
4749
4789
  _renderEmptyEditorContent(emptyEl) {
4750
4790
  if (!emptyEl) return;
4751
- const fileBtns = this._orderedFileNames().map(f => {
4752
- const ext = f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
4753
- return `
4754
- <button type="button" class="codelab-empty-file-btn" data-cl-file="${escapeHtml(f)}" title="Open ${escapeHtml(f)}">
4755
- <span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext.toUpperCase()}</span>
4756
- <span>${escapeHtml(f)}</span>
4757
- </button>
4758
- `;
4759
- }).join('');
4760
-
4761
4791
  emptyEl.innerHTML = `
4762
4792
  <div class="codelab-empty-editor__inner">
4763
- <div class="codelab-empty-editor__icon" aria-hidden="true">
4764
- <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
4765
- <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"/>
4766
- <polyline points="14 2 14 8 20 8"/>
4767
- </svg>
4768
- </div>
4769
- <h2 class="codelab-empty-editor__title">No Open Editors</h2>
4770
- <p class="codelab-empty-editor__subtitle">Select a file from the explorer on the left or click a workspace file below to open.</p>
4771
- <div class="codelab-empty-editor__files" role="group" aria-label="Workspace Files">
4772
- ${fileBtns}
4773
- </div>
4774
- <div class="codelab-empty-editor__actions">
4775
- <button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⇧⌘↵)">
4776
- ${CL_ICONS.play}
4777
- <span>Run Demo</span>
4778
- <span class="codelab-btn__kbd">⇧⌘↵</span>
4793
+ <div class="codelab-empty-editor__watermark" aria-hidden="true">code-lab</div>
4794
+ <div class="codelab-empty-editor__shortcuts" role="group" aria-label="Quick actions">
4795
+ <button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette-files">
4796
+ <span>Go to File</span><kbd>⌘P</kbd>
4779
4797
  </button>
4780
- <button type="button" class="codelab-btn codelab-btn--test" data-cl-action="run-tests" title="Run Test Suite (⌘↵)">
4781
- ${CL_ICONS.check}
4782
- <span>Run Tests</span>
4783
- <span class="codelab-btn__kbd">⌘↵</span>
4798
+ <button type="button" class="codelab-empty-shortcut" data-cl-action="command-palette">
4799
+ <span>Show All Commands</span><kbd>⌘⇧P</kbd>
4784
4800
  </button>
4785
4801
  </div>
4802
+ <p class="codelab-empty-editor__subtitle">No editors open. Select a file from the Explorer to start editing.</p>
4786
4803
  </div>
4787
4804
  `;
4788
4805
  }
@@ -4852,7 +4869,7 @@ declare module 'bun:sqlite' {
4852
4869
  this.openCommandPalette('files');
4853
4870
  return;
4854
4871
  }
4855
- if ((e.metaKey || e.ctrlKey) && keyLower === 'c') {
4872
+ if (e.ctrlKey && !e.metaKey && keyLower === 'c') {
4856
4873
  const hasSelection = typeof window !== 'undefined' && window.getSelection && window.getSelection().toString().length > 0;
4857
4874
  if (!hasSelection && (this.isRunning || this._activeCommandAbortController)) {
4858
4875
  e.preventDefault();
@@ -5154,6 +5171,7 @@ declare module 'bun:sqlite' {
5154
5171
  if (action === 'run-demo') this.runDemo();
5155
5172
  else if (action === 'run-tests') this.runTests();
5156
5173
  else if (action === 'stop-run') this.stopExecution();
5174
+ else if (action === 'interrupt') this._handleInterrupt();
5157
5175
  else if (action === 'verify-step') this.verifyCurrentStep();
5158
5176
  else if (action === 'show-diff') this.showSolutionModal();
5159
5177
  else if (action === 'compare-diff') {
@@ -5747,6 +5765,48 @@ declare module 'bun:sqlite' {
5747
5765
  hSplitter.addEventListener('pointerup', onUp);
5748
5766
  });
5749
5767
  }
5768
+
5769
+ const fSplitter = this.container.querySelector('#cl-splitter-files');
5770
+ if (fSplitter) {
5771
+ const applyWidth = (w) => {
5772
+ this.explorerWidth = Math.round(w);
5773
+ shell.style.setProperty('--cl-explorer-width', `${this.explorerWidth}px`);
5774
+ if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
5775
+ };
5776
+
5777
+ fSplitter.addEventListener('dblclick', () => {
5778
+ applyWidth(196);
5779
+ this._saveState();
5780
+ });
5781
+
5782
+ fSplitter.addEventListener('pointerdown', e => {
5783
+ e.preventDefault();
5784
+ fSplitter.classList.add('is-dragging');
5785
+ shell.classList.add('is-resizing');
5786
+ try { fSplitter.setPointerCapture(e.pointerId); } catch (_) {}
5787
+
5788
+ const onMove = ev => {
5789
+ const ws = this.container.querySelector('.codelab-workspace');
5790
+ const rect = (ws || shell).getBoundingClientRect();
5791
+ const minW = 140;
5792
+ const maxW = Math.max(minW, Math.floor(rect.width * 0.5));
5793
+ const nextW = Math.min(maxW, Math.max(minW, Math.round(ev.clientX - rect.left)));
5794
+ applyWidth(nextW);
5795
+ };
5796
+
5797
+ const onUp = ev => {
5798
+ fSplitter.classList.remove('is-dragging');
5799
+ shell.classList.remove('is-resizing');
5800
+ try { fSplitter.releasePointerCapture(ev.pointerId); } catch (_) {}
5801
+ fSplitter.removeEventListener('pointermove', onMove);
5802
+ fSplitter.removeEventListener('pointerup', onUp);
5803
+ this._saveState();
5804
+ };
5805
+
5806
+ fSplitter.addEventListener('pointermove', onMove);
5807
+ fSplitter.addEventListener('pointerup', onUp);
5808
+ });
5809
+ }
5750
5810
  }
5751
5811
 
5752
5812
  selectStep(idx, shouldJump = true) {
@@ -6143,6 +6203,12 @@ declare module 'bun:sqlite' {
6143
6203
  }
6144
6204
 
6145
6205
  // ── Execution Engine (Web Worker + Virtual Node Runtime) ───────────────
6206
+ _isAbortResult(res, signal) {
6207
+ if (signal && signal.aborted) return true;
6208
+ if (!res || typeof res !== 'object') return false;
6209
+ return Boolean(res.cancelled || res.aborted || res.exitCode === 130);
6210
+ }
6211
+
6146
6212
  async _executeRuntime(execOptions) {
6147
6213
  const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
6148
6214
  const payload = {
@@ -6179,7 +6245,11 @@ declare module 'bun:sqlite' {
6179
6245
  this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
6180
6246
  return res;
6181
6247
  } catch (err) {
6182
- this._setRuntimeStatus('error', 'Execution error');
6248
+ if (payload.signal && payload.signal.aborted) {
6249
+ this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
6250
+ } else {
6251
+ this._setRuntimeStatus('error', 'Execution error');
6252
+ }
6183
6253
  throw err;
6184
6254
  }
6185
6255
  }
@@ -6221,18 +6291,21 @@ declare module 'bun:sqlite' {
6221
6291
  }
6222
6292
  });
6223
6293
  this._flushTerminalStream();
6294
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
6224
6295
 
6225
- if (!streamedStdout && res.stdout) {
6296
+ if (!aborted && !streamedStdout && res.stdout) {
6226
6297
  this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
6227
6298
  }
6228
- if (!streamedStderr && res.stderr) {
6299
+ if (!aborted && !streamedStderr && res.stderr) {
6229
6300
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
6230
6301
  }
6231
- if (res.error) {
6302
+ if (!aborted && res.error) {
6232
6303
  this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
6233
6304
  }
6234
- this.lastFsSnapshot = res.fsSnapshot || [];
6235
- this.lastHttpTrace = res.httpTrace || [];
6305
+ if (!aborted) {
6306
+ this.lastFsSnapshot = res.fsSnapshot || [];
6307
+ this.lastHttpTrace = res.httpTrace || [];
6308
+ }
6236
6309
 
6237
6310
  if (this.onRun) {
6238
6311
  try { this.onRun(res); } catch (_) {}
@@ -6240,7 +6313,9 @@ declare module 'bun:sqlite' {
6240
6313
  this._emitEvent('codelab:run', { labId: this.labId, mode: 'run', entry, result: res });
6241
6314
  } catch (err) {
6242
6315
  this._flushTerminalStream();
6243
- this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
6316
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
6317
+ this.terminalLogs.push({ type: 'stderr', text: `Execution error: ${formatErrorText(err)}` });
6318
+ }
6244
6319
  } finally {
6245
6320
  if (this._activeCommandAbortController === abortCtrl) {
6246
6321
  this._activeCommandAbortController = null;
@@ -6289,18 +6364,21 @@ declare module 'bun:sqlite' {
6289
6364
  }
6290
6365
  });
6291
6366
  this._flushTerminalStream();
6367
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
6292
6368
 
6293
- this.lastTestResults = res.testResults || [];
6294
- this.lastFsSnapshot = res.fsSnapshot || [];
6295
- this.lastHttpTrace = res.httpTrace || [];
6369
+ if (!aborted) {
6370
+ this.lastTestResults = res.testResults || [];
6371
+ this.lastFsSnapshot = res.fsSnapshot || [];
6372
+ this.lastHttpTrace = res.httpTrace || [];
6373
+ }
6296
6374
 
6297
- if (!streamedStdout && res.stdout) {
6375
+ if (!aborted && !streamedStdout && res.stdout) {
6298
6376
  this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
6299
6377
  }
6300
- if (!streamedStderr && res.stderr) {
6378
+ if (!aborted && !streamedStderr && res.stderr) {
6301
6379
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
6302
6380
  }
6303
- if (res.error) {
6381
+ if (!aborted && res.error) {
6304
6382
  this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
6305
6383
  }
6306
6384
 
@@ -6351,7 +6429,9 @@ declare module 'bun:sqlite' {
6351
6429
  }
6352
6430
  } catch (err) {
6353
6431
  this._flushTerminalStream();
6354
- this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
6432
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
6433
+ this.terminalLogs.push({ type: 'stderr', text: `Test runner error: ${formatErrorText(err)}` });
6434
+ }
6355
6435
  } finally {
6356
6436
  if (this._activeCommandAbortController === abortCtrl) {
6357
6437
  this._activeCommandAbortController = null;
@@ -6442,16 +6522,19 @@ declare module 'bun:sqlite' {
6442
6522
  onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
6443
6523
  });
6444
6524
  this._flushTerminalStream();
6525
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
6445
6526
  const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
6446
- if (!streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
6447
- if (!streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
6448
- if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
6527
+ if (!aborted && !streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
6528
+ if (!aborted && !streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
6529
+ if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
6449
6530
  this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
6450
6531
  }
6451
- if (res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
6532
+ if (!aborted && res.error) this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
6452
6533
  } catch (err) {
6453
6534
  this._flushTerminalStream();
6454
- this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6535
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
6536
+ this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6537
+ }
6455
6538
  } finally {
6456
6539
  if (this._activeCommandAbortController === abortCtrl) {
6457
6540
  this._activeCommandAbortController = null;
@@ -6510,6 +6593,7 @@ declare module 'bun:sqlite' {
6510
6593
  signal: abortCtrl.signal
6511
6594
  });
6512
6595
  this._flushTerminalStream();
6596
+ const aborted = this._isAbortResult(shellRes, abortCtrl.signal);
6513
6597
  this.cwd = this.shell.cwd || this.cwd;
6514
6598
  this._syncVfsSnapshot(null, true);
6515
6599
 
@@ -6529,10 +6613,10 @@ declare module 'bun:sqlite' {
6529
6613
 
6530
6614
  const isCmdNotFound = shellRes && shellRes.exitCode === 127 && typeof shellRes.stderr === 'string' && shellRes.stderr.includes('command not found');
6531
6615
  if (!isCmdNotFound) {
6532
- if (shellRes && shellRes.stdout && !streamedStdout) {
6616
+ if (!aborted && shellRes && shellRes.stdout && !streamedStdout) {
6533
6617
  this.terminalLogs.push({ type: 'stdout', text: shellRes.stdout.replace(/\n$/, '') });
6534
6618
  }
6535
- if (shellRes && shellRes.stderr && !streamedStderr) {
6619
+ if (!aborted && shellRes && shellRes.stderr && !streamedStderr) {
6536
6620
  this.terminalLogs.push({ type: 'stderr', text: shellRes.stderr.replace(/\n$/, '') });
6537
6621
  }
6538
6622
  this._renderDrawerBody();
@@ -6545,7 +6629,9 @@ declare module 'bun:sqlite' {
6545
6629
  }
6546
6630
  } catch (err) {
6547
6631
  this._flushTerminalStream();
6548
- this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6632
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
6633
+ this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6634
+ }
6549
6635
  this._renderDrawerBody();
6550
6636
  return;
6551
6637
  } finally {
@@ -6581,17 +6667,18 @@ declare module 'bun:sqlite' {
6581
6667
  }
6582
6668
  });
6583
6669
  this._flushTerminalStream();
6670
+ const aborted = this._isAbortResult(res, fallbackAbortCtrl.signal);
6584
6671
  const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
6585
- if (!streamedFallbackStdout && cleanStdout) {
6672
+ if (!aborted && !streamedFallbackStdout && cleanStdout) {
6586
6673
  this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
6587
6674
  }
6588
- if (!streamedFallbackStderr && res.stderr) {
6675
+ if (!aborted && !streamedFallbackStderr && res.stderr) {
6589
6676
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
6590
6677
  }
6591
- if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
6678
+ if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
6592
6679
  this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
6593
6680
  }
6594
- if (res.error) {
6681
+ if (!aborted && res.error) {
6595
6682
  const errStr = formatErrorText(res.error);
6596
6683
  if (/^[a-zA-Z0-9_-]+$/.test(trimmed) && errStr.includes(`ReferenceError: ${trimmed} is not defined`)) {
6597
6684
  this.terminalLogs.push({ type: 'stderr', text: `codelab: ${trimmed}: command not found (type "help" for commands or enter a JS/TS expression)` });
@@ -6601,7 +6688,9 @@ declare module 'bun:sqlite' {
6601
6688
  }
6602
6689
  } catch (err) {
6603
6690
  this._flushTerminalStream();
6604
- this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6691
+ if (!(fallbackAbortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
6692
+ this.terminalLogs.push({ type: 'stderr', text: formatErrorText(err) });
6693
+ }
6605
6694
  } finally {
6606
6695
  if (this._activeCommandAbortController === fallbackAbortCtrl) {
6607
6696
  this._activeCommandAbortController = null;
@@ -6853,8 +6942,13 @@ declare module 'bun:sqlite' {
6853
6942
  const intoRoot = options.intoRoot !== false;
6854
6943
  const targetDir = intoRoot ? '/workspace' : `/workspace/${parsed.repo}`;
6855
6944
  const cmdDisplay = `git clone ${repoInput}${intoRoot ? ' .' : ''}`;
6945
+ this.drawerTab = 'terminal';
6856
6946
  this.terminalLogs.push({ type: 'cmd', text: cmdDisplay });
6947
+ this.isRunning = true;
6948
+ const abortCtrl = new AbortController();
6949
+ this._activeCommandAbortController = abortCtrl;
6857
6950
  this._renderDrawerBody();
6951
+ this._updateRunStateUI();
6858
6952
 
6859
6953
  try {
6860
6954
  if (intoRoot && this.shell && this.shell.vfs) {
@@ -6877,6 +6971,7 @@ declare module 'bun:sqlite' {
6877
6971
  maxFiles: options.maxFiles || 250,
6878
6972
  maxFileSize: options.maxFileSize || 512 * 1024,
6879
6973
  fetchImpl: options.fetchImpl || (this.shell && this.shell.options ? this.shell.options.fetchImpl : undefined),
6974
+ signal: abortCtrl.signal,
6880
6975
  onProgress: options.onProgress
6881
6976
  });
6882
6977
 
@@ -6948,10 +7043,18 @@ declare module 'bun:sqlite' {
6948
7043
  this._emitEvent('repo:cloned', eventDetail);
6949
7044
  return result;
6950
7045
  } catch (err) {
6951
- const msg = err && err.message ? err.message : String(err);
6952
- this.terminalLogs.push({ type: 'stderr', text: msg });
7046
+ if (!(abortCtrl.signal.aborted || (err && err.name === 'AbortError'))) {
7047
+ const msg = err && err.message ? err.message : String(err);
7048
+ this.terminalLogs.push({ type: 'stderr', text: msg });
7049
+ }
6953
7050
  this._renderDrawerBody();
6954
7051
  throw err;
7052
+ } finally {
7053
+ if (this._activeCommandAbortController === abortCtrl) {
7054
+ this._activeCommandAbortController = null;
7055
+ }
7056
+ this.isRunning = false;
7057
+ this._updateRunStateUI();
6955
7058
  }
6956
7059
  }
6957
7060