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