@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/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();
@@ -18115,6 +18161,39 @@ declare module 'bun:sqlite' {
18115
18161
  const termSurface = this.container ? this.container.querySelector('#cl-terminal-surface') : null;
18116
18162
  const drawerBody = this.container ? this.container.querySelector('.codelab-drawer__body') : null;
18117
18163
 
18164
+ // The workbench owns live terminal rendering. Only defer when an attached PTY
18165
+ // engine is itself rendering into the DOM (it is created with a null container in
18166
+ // production, so this remains the sole renderer there).
18167
+ const ptyOwnsDom = Boolean(this.ptyEngine && this.ptyEngine.container);
18168
+ const canPatchDom = Boolean(termLogEl && typeof document !== 'undefined' && !ptyOwnsDom);
18169
+
18170
+ // Write a single logical line into the live terminal DOM immediately, so output
18171
+ // streams in as it is produced instead of appearing only when the command ends and
18172
+ // the whole drawer is re-rendered. Reuses the current partial-line element when it
18173
+ // is still attached (carriage-return overwrites / keep-alive updates).
18174
+ const patchLineInDom = (text) => {
18175
+ if (!canPatchDom) return;
18176
+ const html = ansiToHtml ? ansiToHtml(text) : escapeHtml(text);
18177
+ if (this._activeStreamEl && this._activeStreamEl.parentNode === termLogEl) {
18178
+ this._activeStreamEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18179
+ this._activeStreamEl.innerHTML = html;
18180
+ } else {
18181
+ const newEl = document.createElement('div');
18182
+ newEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18183
+ newEl.innerHTML = html;
18184
+ termLogEl.appendChild(newEl);
18185
+ this._activeStreamEl = newEl;
18186
+ }
18187
+ };
18188
+
18189
+ // A newline completes the current line: commit it to the log + DOM, then begin a fresh line.
18190
+ const commitActiveLine = () => {
18191
+ this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
18192
+ patchLineInDom(this._activeStreamLine);
18193
+ this._activeStreamLine = '';
18194
+ this._activeStreamEl = null;
18195
+ };
18196
+
18118
18197
  let i = 0;
18119
18198
  while (i < rawText.length) {
18120
18199
  if (rawText.startsWith('\x1b[2K', i)) {
@@ -18149,20 +18228,22 @@ declare module 'bun:sqlite' {
18149
18228
  const ch = rawText[i];
18150
18229
  if (ch === '\r') {
18151
18230
  if (i + 1 < rawText.length && rawText[i + 1] === '\n') {
18152
- this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
18153
- this._activeStreamLine = '';
18154
- this._activeStreamEl = null;
18231
+ commitActiveLine();
18155
18232
  i += 2;
18156
18233
  continue;
18157
18234
  } else {
18235
+ // Bare carriage return: flush the current text into the active line, then
18236
+ // keep overwriting that same DOM node (no extra line is appended).
18237
+ const rendered = this._activeStreamLine;
18238
+ if (rendered || this._activeStreamEl) {
18239
+ patchLineInDom(rendered);
18240
+ }
18158
18241
  this._activeStreamLine = '';
18159
18242
  i++;
18160
18243
  continue;
18161
18244
  }
18162
18245
  } else if (ch === '\n') {
18163
- this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
18164
- this._activeStreamLine = '';
18165
- this._activeStreamEl = null;
18246
+ commitActiveLine();
18166
18247
  i++;
18167
18248
  continue;
18168
18249
  } else {
@@ -18171,20 +18252,9 @@ declare module 'bun:sqlite' {
18171
18252
  }
18172
18253
  }
18173
18254
 
18174
- if (termLogEl && typeof document !== 'undefined') {
18175
- if (this._activeStreamLine) {
18176
- const formattedHtml = ansiToHtml ? ansiToHtml(this._activeStreamLine) : escapeHtml(this._activeStreamLine);
18177
- if (this._activeStreamEl && this._activeStreamEl.parentNode === termLogEl) {
18178
- this._activeStreamEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18179
- this._activeStreamEl.innerHTML = formattedHtml;
18180
- } else {
18181
- const newEl = document.createElement('div');
18182
- newEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18183
- newEl.innerHTML = formattedHtml;
18184
- termLogEl.appendChild(newEl);
18185
- this._activeStreamEl = newEl;
18186
- }
18187
- }
18255
+ // Render the still-open partial line so incremental progress stays visible.
18256
+ if (this._activeStreamLine) {
18257
+ patchLineInDom(this._activeStreamLine);
18188
18258
  }
18189
18259
 
18190
18260
  if (termSurface) {
@@ -19709,41 +19779,18 @@ declare module 'bun:sqlite' {
19709
19779
 
19710
19780
  _renderEmptyEditorContent(emptyEl) {
19711
19781
  if (!emptyEl) return;
19712
- const fileBtns = this._orderedFileNames().map(f => {
19713
- const ext = f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
19714
- return `
19715
- <button type="button" class="codelab-empty-file-btn" data-cl-file="${escapeHtml(f)}" title="Open ${escapeHtml(f)}">
19716
- <span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext.toUpperCase()}</span>
19717
- <span>${escapeHtml(f)}</span>
19718
- </button>
19719
- `;
19720
- }).join('');
19721
-
19722
19782
  emptyEl.innerHTML = `
19723
19783
  <div class="codelab-empty-editor__inner">
19724
- <div class="codelab-empty-editor__icon" aria-hidden="true">
19725
- <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
19726
- <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"/>
19727
- <polyline points="14 2 14 8 20 8"/>
19728
- </svg>
19729
- </div>
19730
- <h2 class="codelab-empty-editor__title">No Open Editors</h2>
19731
- <p class="codelab-empty-editor__subtitle">Select a file from the explorer on the left or click a workspace file below to open.</p>
19732
- <div class="codelab-empty-editor__files" role="group" aria-label="Workspace Files">
19733
- ${fileBtns}
19734
- </div>
19735
- <div class="codelab-empty-editor__actions">
19736
- <button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⇧⌘↵)">
19737
- ${CL_ICONS.play}
19738
- <span>Run Demo</span>
19739
- <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>
19740
19788
  </button>
19741
- <button type="button" class="codelab-btn codelab-btn--test" data-cl-action="run-tests" title="Run Test Suite (⌘↵)">
19742
- ${CL_ICONS.check}
19743
- <span>Run Tests</span>
19744
- <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>
19745
19791
  </button>
19746
19792
  </div>
19793
+ <p class="codelab-empty-editor__subtitle">No editors open. Select a file from the Explorer to start editing.</p>
19747
19794
  </div>
19748
19795
  `;
19749
19796
  }
@@ -19813,7 +19860,7 @@ declare module 'bun:sqlite' {
19813
19860
  this.openCommandPalette('files');
19814
19861
  return;
19815
19862
  }
19816
- if ((e.metaKey || e.ctrlKey) && keyLower === 'c') {
19863
+ if (e.ctrlKey && !e.metaKey && keyLower === 'c') {
19817
19864
  const hasSelection = typeof window !== 'undefined' && window.getSelection && window.getSelection().toString().length > 0;
19818
19865
  if (!hasSelection && (this.isRunning || this._activeCommandAbortController)) {
19819
19866
  e.preventDefault();
@@ -20115,6 +20162,7 @@ declare module 'bun:sqlite' {
20115
20162
  if (action === 'run-demo') this.runDemo();
20116
20163
  else if (action === 'run-tests') this.runTests();
20117
20164
  else if (action === 'stop-run') this.stopExecution();
20165
+ else if (action === 'interrupt') this._handleInterrupt();
20118
20166
  else if (action === 'verify-step') this.verifyCurrentStep();
20119
20167
  else if (action === 'show-diff') this.showSolutionModal();
20120
20168
  else if (action === 'compare-diff') {
@@ -20708,6 +20756,48 @@ declare module 'bun:sqlite' {
20708
20756
  hSplitter.addEventListener('pointerup', onUp);
20709
20757
  });
20710
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
+ }
20711
20801
  }
20712
20802
 
20713
20803
  selectStep(idx, shouldJump = true) {
@@ -21104,6 +21194,12 @@ declare module 'bun:sqlite' {
21104
21194
  }
21105
21195
 
21106
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
+
21107
21203
  async _executeRuntime(execOptions) {
21108
21204
  const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
21109
21205
  const payload = {
@@ -21140,7 +21236,11 @@ declare module 'bun:sqlite' {
21140
21236
  this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
21141
21237
  return res;
21142
21238
  } catch (err) {
21143
- 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
+ }
21144
21244
  throw err;
21145
21245
  }
21146
21246
  }
@@ -21182,18 +21282,21 @@ declare module 'bun:sqlite' {
21182
21282
  }
21183
21283
  });
21184
21284
  this._flushTerminalStream();
21285
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
21185
21286
 
21186
- if (!streamedStdout && res.stdout) {
21287
+ if (!aborted && !streamedStdout && res.stdout) {
21187
21288
  this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
21188
21289
  }
21189
- if (!streamedStderr && res.stderr) {
21290
+ if (!aborted && !streamedStderr && res.stderr) {
21190
21291
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
21191
21292
  }
21192
- if (res.error) {
21293
+ if (!aborted && res.error) {
21193
21294
  this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
21194
21295
  }
21195
- this.lastFsSnapshot = res.fsSnapshot || [];
21196
- this.lastHttpTrace = res.httpTrace || [];
21296
+ if (!aborted) {
21297
+ this.lastFsSnapshot = res.fsSnapshot || [];
21298
+ this.lastHttpTrace = res.httpTrace || [];
21299
+ }
21197
21300
 
21198
21301
  if (this.onRun) {
21199
21302
  try { this.onRun(res); } catch (_) {}
@@ -21201,7 +21304,9 @@ declare module 'bun:sqlite' {
21201
21304
  this._emitEvent('codelab:run', { labId: this.labId, mode: 'run', entry, result: res });
21202
21305
  } catch (err) {
21203
21306
  this._flushTerminalStream();
21204
- 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
+ }
21205
21310
  } finally {
21206
21311
  if (this._activeCommandAbortController === abortCtrl) {
21207
21312
  this._activeCommandAbortController = null;
@@ -21250,18 +21355,21 @@ declare module 'bun:sqlite' {
21250
21355
  }
21251
21356
  });
21252
21357
  this._flushTerminalStream();
21358
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
21253
21359
 
21254
- this.lastTestResults = res.testResults || [];
21255
- this.lastFsSnapshot = res.fsSnapshot || [];
21256
- this.lastHttpTrace = res.httpTrace || [];
21360
+ if (!aborted) {
21361
+ this.lastTestResults = res.testResults || [];
21362
+ this.lastFsSnapshot = res.fsSnapshot || [];
21363
+ this.lastHttpTrace = res.httpTrace || [];
21364
+ }
21257
21365
 
21258
- if (!streamedStdout && res.stdout) {
21366
+ if (!aborted && !streamedStdout && res.stdout) {
21259
21367
  this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
21260
21368
  }
21261
- if (!streamedStderr && res.stderr) {
21369
+ if (!aborted && !streamedStderr && res.stderr) {
21262
21370
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
21263
21371
  }
21264
- if (res.error) {
21372
+ if (!aborted && res.error) {
21265
21373
  this.terminalLogs.push({ type: 'stderr', text: formatErrorText(res.error) });
21266
21374
  }
21267
21375
 
@@ -21312,7 +21420,9 @@ declare module 'bun:sqlite' {
21312
21420
  }
21313
21421
  } catch (err) {
21314
21422
  this._flushTerminalStream();
21315
- 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
+ }
21316
21426
  } finally {
21317
21427
  if (this._activeCommandAbortController === abortCtrl) {
21318
21428
  this._activeCommandAbortController = null;
@@ -21403,16 +21513,19 @@ declare module 'bun:sqlite' {
21403
21513
  onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
21404
21514
  });
21405
21515
  this._flushTerminalStream();
21516
+ const aborted = this._isAbortResult(res, abortCtrl.signal);
21406
21517
  const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
21407
- if (!streamedStdout && cleanStdout) this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
21408
- if (!streamedStderr && res.stderr) this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
21409
- 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)) {
21410
21521
  this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
21411
21522
  }
21412
- 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) });
21413
21524
  } catch (err) {
21414
21525
  this._flushTerminalStream();
21415
- 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
+ }
21416
21529
  } finally {
21417
21530
  if (this._activeCommandAbortController === abortCtrl) {
21418
21531
  this._activeCommandAbortController = null;
@@ -21471,6 +21584,7 @@ declare module 'bun:sqlite' {
21471
21584
  signal: abortCtrl.signal
21472
21585
  });
21473
21586
  this._flushTerminalStream();
21587
+ const aborted = this._isAbortResult(shellRes, abortCtrl.signal);
21474
21588
  this.cwd = this.shell.cwd || this.cwd;
21475
21589
  this._syncVfsSnapshot(null, true);
21476
21590
 
@@ -21490,10 +21604,10 @@ declare module 'bun:sqlite' {
21490
21604
 
21491
21605
  const isCmdNotFound = shellRes && shellRes.exitCode === 127 && typeof shellRes.stderr === 'string' && shellRes.stderr.includes('command not found');
21492
21606
  if (!isCmdNotFound) {
21493
- if (shellRes && shellRes.stdout && !streamedStdout) {
21607
+ if (!aborted && shellRes && shellRes.stdout && !streamedStdout) {
21494
21608
  this.terminalLogs.push({ type: 'stdout', text: shellRes.stdout.replace(/\n$/, '') });
21495
21609
  }
21496
- if (shellRes && shellRes.stderr && !streamedStderr) {
21610
+ if (!aborted && shellRes && shellRes.stderr && !streamedStderr) {
21497
21611
  this.terminalLogs.push({ type: 'stderr', text: shellRes.stderr.replace(/\n$/, '') });
21498
21612
  }
21499
21613
  this._renderDrawerBody();
@@ -21506,7 +21620,9 @@ declare module 'bun:sqlite' {
21506
21620
  }
21507
21621
  } catch (err) {
21508
21622
  this._flushTerminalStream();
21509
- 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
+ }
21510
21626
  this._renderDrawerBody();
21511
21627
  return;
21512
21628
  } finally {
@@ -21542,17 +21658,18 @@ declare module 'bun:sqlite' {
21542
21658
  }
21543
21659
  });
21544
21660
  this._flushTerminalStream();
21661
+ const aborted = this._isAbortResult(res, fallbackAbortCtrl.signal);
21545
21662
  const cleanStdout = res.stdout ? res.stdout.replace(/\n$/, '') : '';
21546
- if (!streamedFallbackStdout && cleanStdout) {
21663
+ if (!aborted && !streamedFallbackStdout && cleanStdout) {
21547
21664
  this.terminalLogs.push({ type: 'stdout', text: cleanStdout });
21548
21665
  }
21549
- if (!streamedFallbackStderr && res.stderr) {
21666
+ if (!aborted && !streamedFallbackStderr && res.stderr) {
21550
21667
  this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
21551
21668
  }
21552
- if (res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
21669
+ if (!aborted && res.replValue !== undefined && cleanStdout !== String(res.replValue)) {
21553
21670
  this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
21554
21671
  }
21555
- if (res.error) {
21672
+ if (!aborted && res.error) {
21556
21673
  const errStr = formatErrorText(res.error);
21557
21674
  if (/^[a-zA-Z0-9_-]+$/.test(trimmed) && errStr.includes(`ReferenceError: ${trimmed} is not defined`)) {
21558
21675
  this.terminalLogs.push({ type: 'stderr', text: `codelab: ${trimmed}: command not found (type "help" for commands or enter a JS/TS expression)` });
@@ -21562,7 +21679,9 @@ declare module 'bun:sqlite' {
21562
21679
  }
21563
21680
  } catch (err) {
21564
21681
  this._flushTerminalStream();
21565
- 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
+ }
21566
21685
  } finally {
21567
21686
  if (this._activeCommandAbortController === fallbackAbortCtrl) {
21568
21687
  this._activeCommandAbortController = null;
@@ -21814,8 +21933,13 @@ declare module 'bun:sqlite' {
21814
21933
  const intoRoot = options.intoRoot !== false;
21815
21934
  const targetDir = intoRoot ? '/workspace' : `/workspace/${parsed.repo}`;
21816
21935
  const cmdDisplay = `git clone ${repoInput}${intoRoot ? ' .' : ''}`;
21936
+ this.drawerTab = 'terminal';
21817
21937
  this.terminalLogs.push({ type: 'cmd', text: cmdDisplay });
21938
+ this.isRunning = true;
21939
+ const abortCtrl = new AbortController();
21940
+ this._activeCommandAbortController = abortCtrl;
21818
21941
  this._renderDrawerBody();
21942
+ this._updateRunStateUI();
21819
21943
 
21820
21944
  try {
21821
21945
  if (intoRoot && this.shell && this.shell.vfs) {
@@ -21838,6 +21962,7 @@ declare module 'bun:sqlite' {
21838
21962
  maxFiles: options.maxFiles || 250,
21839
21963
  maxFileSize: options.maxFileSize || 512 * 1024,
21840
21964
  fetchImpl: options.fetchImpl || (this.shell && this.shell.options ? this.shell.options.fetchImpl : undefined),
21965
+ signal: abortCtrl.signal,
21841
21966
  onProgress: options.onProgress
21842
21967
  });
21843
21968
 
@@ -21909,10 +22034,18 @@ declare module 'bun:sqlite' {
21909
22034
  this._emitEvent('repo:cloned', eventDetail);
21910
22035
  return result;
21911
22036
  } catch (err) {
21912
- const msg = err && err.message ? err.message : String(err);
21913
- 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
+ }
21914
22041
  this._renderDrawerBody();
21915
22042
  throw err;
22043
+ } finally {
22044
+ if (this._activeCommandAbortController === abortCtrl) {
22045
+ this._activeCommandAbortController = null;
22046
+ }
22047
+ this.isRunning = false;
22048
+ this._updateRunStateUI();
21916
22049
  }
21917
22050
  }
21918
22051