@innovatorved/code-lab 0.1.0 → 0.1.2

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
@@ -9479,6 +9479,10 @@ if (typeof module !== 'undefined' && module.exports) {
9479
9479
  }
9480
9480
 
9481
9481
  async function cloneGitHubRepository(repoInput, vfs, options = {}) {
9482
+ const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
9483
+ if (onProgress) {
9484
+ onProgress({ phase: 'connecting', message: `Connecting to repository '${repoInput}'...` });
9485
+ }
9482
9486
  const parsed = parseGitHubRepoUrl(repoInput);
9483
9487
  if (!parsed) {
9484
9488
  throw new Error(`fatal: repository '${repoInput}' does not exist or is not a valid GitHub repository URL`);
@@ -9502,6 +9506,10 @@ if (typeof module !== 'undefined' && module.exports) {
9502
9506
  let rawTreeEntries = null;
9503
9507
  let repoNotFound = false;
9504
9508
 
9509
+ if (onProgress) {
9510
+ onProgress({ phase: 'metadata', message: `Fetching repository metadata for ${owner}/${repo}...` });
9511
+ }
9512
+
9505
9513
  // Strategy A: GitHub REST API (with automatic fallback if rate-limited)
9506
9514
  try {
9507
9515
  if (!resolvedBranch) {
@@ -9606,6 +9614,11 @@ if (typeof module !== 'undefined' && module.exports) {
9606
9614
 
9607
9615
  filtered.sort((a, b) => a.priority - b.priority || a.destPath.localeCompare(b.destPath));
9608
9616
  const selectedFiles = filtered.slice(0, maxFiles);
9617
+ const totalToDownload = selectedFiles.length;
9618
+
9619
+ if (onProgress) {
9620
+ onProgress({ phase: 'downloading', message: `Downloading files (0/${totalToDownload})...`, loaded: 0, total: totalToDownload });
9621
+ }
9609
9622
 
9610
9623
  if (!vfs.existsSync(targetDir)) {
9611
9624
  vfs.mkdirSync(targetDir, { recursive: true });
@@ -9651,6 +9664,9 @@ if (typeof module !== 'undefined' && module.exports) {
9651
9664
  headSnapshot[entry.destPath] = text;
9652
9665
  filesWritten++;
9653
9666
  totalBytes += text.length;
9667
+ if (onProgress) {
9668
+ onProgress({ phase: 'downloading', message: `Downloading files (${filesWritten}/${totalToDownload}): ${entry.destPath}`, loaded: filesWritten, total: totalToDownload });
9669
+ }
9654
9670
  if (typeof options.onFile === 'function') {
9655
9671
  options.onFile(absPath, text, entry.destPath);
9656
9672
  }
@@ -9659,6 +9675,10 @@ if (typeof module !== 'undefined' && module.exports) {
9659
9675
  );
9660
9676
  }
9661
9677
 
9678
+ if (onProgress) {
9679
+ onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
9680
+ }
9681
+
9662
9682
  // Write .git metadata inside targetDir
9663
9683
  const gitDir = PosixPath.join(targetDir, '.git');
9664
9684
  if (!vfs.existsSync(gitDir)) {
@@ -9707,6 +9727,10 @@ if (typeof module !== 'undefined' && module.exports) {
9707
9727
  ];
9708
9728
  }
9709
9729
 
9730
+ if (onProgress) {
9731
+ onProgress({ phase: 'ready', message: `Repository cloned successfully (${filesWritten} files).`, loaded: filesWritten, total: totalToDownload });
9732
+ }
9733
+
9710
9734
  return {
9711
9735
  owner,
9712
9736
  repo,
@@ -11906,12 +11930,37 @@ if (typeof module !== 'undefined' && module.exports) {
11906
11930
  dirDisplayName = parsed.repo;
11907
11931
  }
11908
11932
 
11933
+ // Stream clone progress to the terminal as it happens (no end-of-run buffering).
11934
+ const canStream = typeof ctx.onStdout === 'function';
11935
+ const streamLine = (text) => { if (canStream && text) ctx.onStdout(text); };
11936
+ streamLine(`Cloning into '${dirDisplayName}'...\n`);
11937
+ let enumeratedEmitted = false;
11938
+ let lastProgressPct = -1;
11939
+
11909
11940
  try {
11910
11941
  const result = await cloneGitHubRepository(repoArg, ctx.vfs, {
11911
11942
  targetDir,
11912
11943
  branch: branchOpt,
11913
11944
  fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
11914
- onFile: (absPath) => ctx.emitMutation('create', absPath)
11945
+ onFile: (absPath) => ctx.emitMutation('create', absPath),
11946
+ onProgress: (ev) => {
11947
+ if (!ev) return;
11948
+ if (ev.phase === 'downloading' && !enumeratedEmitted && typeof ev.total === 'number' && ev.total > 0) {
11949
+ enumeratedEmitted = true;
11950
+ streamLine(`remote: Enumerating objects: ${ev.total}, done.\n`);
11951
+ streamLine(`remote: Counting objects: 100% (${ev.total}/${ev.total}), done.\n`);
11952
+ }
11953
+ if (ev.phase === 'downloading' && typeof ev.total === 'number' && ev.total > 0 && typeof ev.loaded === 'number' && ev.loaded < ev.total) {
11954
+ const pct = Math.min(100, Math.max(0, Math.floor((ev.loaded / ev.total) * 100)));
11955
+ if (pct >= lastProgressPct + 10) {
11956
+ lastProgressPct = pct;
11957
+ streamLine(`Receiving objects: ${pct}% (${ev.loaded}/${ev.total})\n`);
11958
+ }
11959
+ }
11960
+ if (ev.phase === 'mounting') {
11961
+ streamLine(`Resolving deltas: 100% (${ev.total || 0}/${ev.total || 0}), done.\n`);
11962
+ }
11963
+ }
11915
11964
  });
11916
11965
 
11917
11966
  gitState.branch = result.branch;
@@ -11925,6 +11974,7 @@ if (typeof module !== 'undefined' && module.exports) {
11925
11974
 
11926
11975
  const count = Math.max(1, result.filesWritten);
11927
11976
  const kb = Math.max(0.1, result.totalBytes / 1024).toFixed(1);
11977
+ streamLine(`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`);
11928
11978
  const stdout =
11929
11979
  `Cloning into '${dirDisplayName}'...\n` +
11930
11980
  `remote: Enumerating objects: ${count}, done.\n` +
@@ -11933,6 +11983,7 @@ if (typeof module !== 'undefined' && module.exports) {
11933
11983
  return { code: 0, stdout, stderr: '' };
11934
11984
  } catch (err) {
11935
11985
  const msg = err && err.message ? err.message : String(err);
11986
+ if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
11936
11987
  return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
11937
11988
  }
11938
11989
  }
@@ -16081,6 +16132,8 @@ declare module 'bun:sqlite' {
16081
16132
  this.completedSteps = new Set(this.savedState.completedSteps || []);
16082
16133
  this.folders = new Set(this.savedState?.folders || []);
16083
16134
  this.collapsedFolders = new Set(this.savedState?.collapsedFolders || []);
16135
+ this.explorerFolder = this.savedState?.explorerFolder || ''; // '' = workspace root, else folder path scope
16136
+ this.folderSwitcherOpen = false;
16084
16137
  this.creatingItem = null; // { type: 'file' | 'folder', parentFolder: string } | null
16085
16138
  this.renamingItem = null;
16086
16139
  this._draggedFile = null;
@@ -16416,7 +16469,8 @@ declare module 'bun:sqlite' {
16416
16469
  openTabs: Array.isArray(this.openTabs) ? [...this.openTabs] : undefined,
16417
16470
  activeFile: this.activeFile,
16418
16471
  folders: Array.from(this.folders || []),
16419
- collapsedFolders: Array.from(this.collapsedFolders || [])
16472
+ collapsedFolders: Array.from(this.collapsedFolders || []),
16473
+ explorerFolder: this.explorerFolder || ''
16420
16474
  };
16421
16475
  this.savedState = state;
16422
16476
  if (this.options && this.options.persistState === false) {
@@ -16860,23 +16914,59 @@ declare module 'bun:sqlite' {
16860
16914
  </button>
16861
16915
  ` : '';
16862
16916
 
16863
- let pathHtml = `<button type="button" class="codelab-breadcrumb__item codelab-breadcrumb__root" data-action="command-palette-files" data-cl-action="command-palette-files" title="Quick Open File (⌘P)">workspace</button>`;
16917
+ const folderOptions = this._listWorkspaceFolders();
16918
+ const scope = this.explorerFolder || '';
16919
+ const scopeLabel = scope ? scope.split('/').pop() : 'workspace';
16920
+
16921
+ const switcherHtml = `
16922
+ <div class="codelab-folder-switcher ${this.folderSwitcherOpen ? 'is-open' : ''}">
16923
+ <button type="button" class="codelab-folder-switcher__toggle ${scope ? 'is-scoped' : ''}" data-cl-action="toggle-folder-switcher" aria-haspopup="true" aria-expanded="${this.folderSwitcherOpen ? 'true' : 'false'}" title="Switch workspace folder">
16924
+ ${CL_ICONS.folder}
16925
+ <span class="codelab-folder-switcher__label">${escapeHtml(scopeLabel)}</span>
16926
+ ${CL_ICONS.chevronDown}
16927
+ </button>
16928
+ ${this.folderSwitcherOpen ? `
16929
+ <div class="codelab-folder-switcher__menu" role="menu" aria-label="Workspace folders">
16930
+ <div class="codelab-folder-switcher__section">Switch Folder</div>
16931
+ <button type="button" role="menuitem" class="codelab-folder-switcher__option ${!scope ? 'active' : ''}" data-cl-folder-option="">
16932
+ <span class="codelab-folder-switcher__icon">${CL_ICONS.folder}</span>
16933
+ <span class="codelab-folder-switcher__name">workspace</span>
16934
+ <span class="codelab-folder-switcher__path">/</span>
16935
+ </button>
16936
+ ${folderOptions.map(f => {
16937
+ const fDepth = f.split('/').length;
16938
+ const fName = f.split('/').pop();
16939
+ return `
16940
+ <button type="button" role="menuitem" class="codelab-folder-switcher__option ${scope === f ? 'active' : ''}" data-cl-folder-option="${escapeHtml(f)}" style="padding-left:${10 + (fDepth - 1) * 12}px;">
16941
+ <span class="codelab-folder-switcher__icon">${CL_ICONS.folder}</span>
16942
+ <span class="codelab-folder-switcher__name">${escapeHtml(fName)}</span>
16943
+ <span class="codelab-folder-switcher__path">${escapeHtml(f)}</span>
16944
+ </button>
16945
+ `;
16946
+ }).join('')}
16947
+ ${folderOptions.length ? '' : '<div class="codelab-folder-switcher__empty">No subfolders yet</div>'}
16948
+ </div>
16949
+ ` : ''}
16950
+ </div>
16951
+ `;
16952
+
16953
+ let pathHtml = `<button type="button" class="codelab-breadcrumbs__item codelab-breadcrumbs__item--root" data-action="command-palette-files" data-cl-action="command-palette-files" title="Quick Open File (⌘P)">workspace</button>`;
16864
16954
 
16865
16955
  if (this.activeFile) {
16866
16956
  const segments = this.activeFile.split('/');
16867
16957
  for (let i = 0; i < segments.length - 1; i++) {
16868
16958
  const folderPath = segments.slice(0, i + 1).join('/');
16869
- pathHtml += `<span class="codelab-breadcrumb__sep" aria-hidden="true">›</span>`;
16870
- pathHtml += `<button type="button" class="codelab-breadcrumb__item codelab-breadcrumb__folder" data-cl-breadcrumb-folder="${escapeHtml(folderPath)}" data-folder="${escapeHtml(folderPath)}">${escapeHtml(segments[i])}</button>`;
16959
+ pathHtml += `<span class="codelab-breadcrumbs__sep" aria-hidden="true">›</span>`;
16960
+ pathHtml += `<button type="button" class="codelab-breadcrumbs__item codelab-breadcrumbs__item--folder" data-cl-breadcrumb-folder="${escapeHtml(folderPath)}" data-folder="${escapeHtml(folderPath)}" title="Scope explorer to ${escapeHtml(folderPath)}">${escapeHtml(segments[i])}</button>`;
16871
16961
  }
16872
16962
  const fileName = segments[segments.length - 1];
16873
- pathHtml += `<span class="codelab-breadcrumb__sep" aria-hidden="true">›</span>`;
16874
- pathHtml += `<button type="button" class="codelab-breadcrumb__item codelab-breadcrumb__file active" data-cl-breadcrumb-file="${escapeHtml(this.activeFile)}" data-file="${escapeHtml(this.activeFile)}">${escapeHtml(fileName)}</button>`;
16963
+ pathHtml += `<span class="codelab-breadcrumbs__sep" aria-hidden="true">›</span>`;
16964
+ pathHtml += `<button type="button" class="codelab-breadcrumbs__item codelab-breadcrumbs__item--file active" data-cl-breadcrumb-file="${escapeHtml(this.activeFile)}" data-file="${escapeHtml(this.activeFile)}">${escapeHtml(fileName)}</button>`;
16875
16965
 
16876
16966
  const symbol = this._detectActiveSymbol(this.activeFile);
16877
16967
  if (symbol) {
16878
- pathHtml += `<span class="codelab-breadcrumb__sep" aria-hidden="true">›</span>`;
16879
- pathHtml += `<span class="codelab-breadcrumb__symbol" data-cl-breadcrumb-symbol="${escapeHtml(symbol)}">ƒ ${escapeHtml(symbol)}</span>`;
16968
+ pathHtml += `<span class="codelab-breadcrumbs__sep" aria-hidden="true">›</span>`;
16969
+ pathHtml += `<span class="codelab-breadcrumbs__item codelab-breadcrumbs__item--symbol" data-cl-breadcrumb-symbol="${escapeHtml(symbol)}">ƒ ${escapeHtml(symbol)}</span>`;
16880
16970
  }
16881
16971
  }
16882
16972
 
@@ -16897,7 +16987,10 @@ declare module 'bun:sqlite' {
16897
16987
 
16898
16988
  host.innerHTML = `
16899
16989
  ${expandBtnHtml}
16900
- <div class="codelab-breadcrumbs__path">${pathHtml}</div>
16990
+ <div class="codelab-breadcrumbs__left">
16991
+ ${switcherHtml}
16992
+ <div class="codelab-breadcrumbs__path">${pathHtml}</div>
16993
+ </div>
16901
16994
  <div class="codelab-breadcrumbs__actions">
16902
16995
  ${diffBtnHtml}
16903
16996
  <button type="button" class="codelab-breadcrumb__btn" data-action="command-palette" data-cl-action="command-palette" title="Open Command Palette (⌘⇧P)">
@@ -17140,6 +17233,36 @@ declare module 'bun:sqlite' {
17140
17233
  return rootNode;
17141
17234
  }
17142
17235
 
17236
+ _listWorkspaceFolders() {
17237
+ const set = new Set();
17238
+ if (this.folders) {
17239
+ for (const f of this.folders) {
17240
+ if (f) set.add(f);
17241
+ }
17242
+ }
17243
+ for (const filePath of this._orderedFileNames()) {
17244
+ const idx = filePath.lastIndexOf('/');
17245
+ if (idx <= 0) continue;
17246
+ const parts = filePath.slice(0, idx).split('/');
17247
+ let running = '';
17248
+ for (const p of parts) {
17249
+ running = running ? `${running}/${p}` : p;
17250
+ set.add(running);
17251
+ }
17252
+ }
17253
+ return Array.from(set).sort((a, b) => a.localeCompare(b));
17254
+ }
17255
+
17256
+ _resolveFolderNode(rootNode, folderPath) {
17257
+ if (!rootNode || !folderPath) return null;
17258
+ let current = rootNode;
17259
+ for (const seg of folderPath.split('/')) {
17260
+ if (!current || !current.folders || !current.folders.has(seg)) return null;
17261
+ current = current.folders.get(seg);
17262
+ }
17263
+ return current || null;
17264
+ }
17265
+
17143
17266
  _renderFileLists() {
17144
17267
  const explorerEl = this.container.querySelector('#cl-explorer-list');
17145
17268
  const tabsEl = this.container.querySelector('#cl-file-tabs');
@@ -17148,6 +17271,12 @@ declare module 'bun:sqlite' {
17148
17271
  if (!explorerEl || !tabsEl) return;
17149
17272
 
17150
17273
  const treeRoot = this._buildFileTree();
17274
+ if (this.explorerFolder && !this._resolveFolderNode(treeRoot, this.explorerFolder)) {
17275
+ this.explorerFolder = '';
17276
+ }
17277
+ const scope = this.explorerFolder || '';
17278
+ const renderRoot = scope ? this._resolveFolderNode(treeRoot, scope) : treeRoot;
17279
+ const rootParent = scope;
17151
17280
  let treeHtml = '';
17152
17281
 
17153
17282
  const renderNode = (node, depth) => {
@@ -17202,7 +17331,7 @@ declare module 'bun:sqlite' {
17202
17331
  }
17203
17332
  };
17204
17333
 
17205
- if (this.creatingItem && this.creatingItem.parentFolder === '') {
17334
+ if (this.creatingItem && this.creatingItem.parentFolder === rootParent) {
17206
17335
  treeHtml += `
17207
17336
  <div class="codelab-tree-create-row" style="padding-left: 10px;">
17208
17337
  <span class="codelab-tree-create-icon">${this.creatingItem.type === 'folder' ? CL_ICONS.folder : CL_ICONS.file}</span>
@@ -17211,7 +17340,16 @@ declare module 'bun:sqlite' {
17211
17340
  `;
17212
17341
  }
17213
17342
 
17214
- renderNode(treeRoot, 0);
17343
+ if (scope) {
17344
+ treeHtml += `
17345
+ <button type="button" class="codelab-scope-up" data-cl-folder-option="" title="Back to workspace root">
17346
+ <span class="codelab-scope-up__arrow">←</span>
17347
+ <span class="codelab-scope-up__label">workspace</span>
17348
+ </button>
17349
+ `;
17350
+ }
17351
+
17352
+ renderNode(renderRoot, 0);
17215
17353
  explorerEl.innerHTML = treeHtml;
17216
17354
 
17217
17355
  // Attach file drag events
@@ -17977,6 +18115,39 @@ declare module 'bun:sqlite' {
17977
18115
  const termSurface = this.container ? this.container.querySelector('#cl-terminal-surface') : null;
17978
18116
  const drawerBody = this.container ? this.container.querySelector('.codelab-drawer__body') : null;
17979
18117
 
18118
+ // The workbench owns live terminal rendering. Only defer when an attached PTY
18119
+ // engine is itself rendering into the DOM (it is created with a null container in
18120
+ // production, so this remains the sole renderer there).
18121
+ const ptyOwnsDom = Boolean(this.ptyEngine && this.ptyEngine.container);
18122
+ const canPatchDom = Boolean(termLogEl && typeof document !== 'undefined' && !ptyOwnsDom);
18123
+
18124
+ // Write a single logical line into the live terminal DOM immediately, so output
18125
+ // streams in as it is produced instead of appearing only when the command ends and
18126
+ // the whole drawer is re-rendered. Reuses the current partial-line element when it
18127
+ // is still attached (carriage-return overwrites / keep-alive updates).
18128
+ const patchLineInDom = (text) => {
18129
+ if (!canPatchDom) return;
18130
+ const html = ansiToHtml ? ansiToHtml(text) : escapeHtml(text);
18131
+ if (this._activeStreamEl && this._activeStreamEl.parentNode === termLogEl) {
18132
+ this._activeStreamEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18133
+ this._activeStreamEl.innerHTML = html;
18134
+ } else {
18135
+ const newEl = document.createElement('div');
18136
+ newEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18137
+ newEl.innerHTML = html;
18138
+ termLogEl.appendChild(newEl);
18139
+ this._activeStreamEl = newEl;
18140
+ }
18141
+ };
18142
+
18143
+ // A newline completes the current line: commit it to the log + DOM, then begin a fresh line.
18144
+ const commitActiveLine = () => {
18145
+ this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
18146
+ patchLineInDom(this._activeStreamLine);
18147
+ this._activeStreamLine = '';
18148
+ this._activeStreamEl = null;
18149
+ };
18150
+
17980
18151
  let i = 0;
17981
18152
  while (i < rawText.length) {
17982
18153
  if (rawText.startsWith('\x1b[2K', i)) {
@@ -18011,20 +18182,22 @@ declare module 'bun:sqlite' {
18011
18182
  const ch = rawText[i];
18012
18183
  if (ch === '\r') {
18013
18184
  if (i + 1 < rawText.length && rawText[i + 1] === '\n') {
18014
- this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
18015
- this._activeStreamLine = '';
18016
- this._activeStreamEl = null;
18185
+ commitActiveLine();
18017
18186
  i += 2;
18018
18187
  continue;
18019
18188
  } else {
18189
+ // Bare carriage return: flush the current text into the active line, then
18190
+ // keep overwriting that same DOM node (no extra line is appended).
18191
+ const rendered = this._activeStreamLine;
18192
+ if (rendered || this._activeStreamEl) {
18193
+ patchLineInDom(rendered);
18194
+ }
18020
18195
  this._activeStreamLine = '';
18021
18196
  i++;
18022
18197
  continue;
18023
18198
  }
18024
18199
  } else if (ch === '\n') {
18025
- this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
18026
- this._activeStreamLine = '';
18027
- this._activeStreamEl = null;
18200
+ commitActiveLine();
18028
18201
  i++;
18029
18202
  continue;
18030
18203
  } else {
@@ -18033,20 +18206,9 @@ declare module 'bun:sqlite' {
18033
18206
  }
18034
18207
  }
18035
18208
 
18036
- if (termLogEl && typeof document !== 'undefined') {
18037
- if (this._activeStreamLine) {
18038
- const formattedHtml = ansiToHtml ? ansiToHtml(this._activeStreamLine) : escapeHtml(this._activeStreamLine);
18039
- if (this._activeStreamEl && this._activeStreamEl.parentNode === termLogEl) {
18040
- this._activeStreamEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18041
- this._activeStreamEl.innerHTML = formattedHtml;
18042
- } else {
18043
- const newEl = document.createElement('div');
18044
- newEl.className = 'codelab-log-line ' + escapeHtml(this._activeStreamType || type);
18045
- newEl.innerHTML = formattedHtml;
18046
- termLogEl.appendChild(newEl);
18047
- this._activeStreamEl = newEl;
18048
- }
18049
- }
18209
+ // Render the still-open partial line so incremental progress stays visible.
18210
+ if (this._activeStreamLine) {
18211
+ patchLineInDom(this._activeStreamLine);
18050
18212
  }
18051
18213
 
18052
18214
  if (termSurface) {
@@ -18772,6 +18934,29 @@ declare module 'bun:sqlite' {
18772
18934
  this._portToasts.delete(p);
18773
18935
  }
18774
18936
 
18937
+ _showToast(message, kind = 'info') {
18938
+ const toastHost = this.container ? this.container.querySelector('#cl-toast-container') : null;
18939
+ if (!toastHost || typeof document === 'undefined') return;
18940
+ const toast = document.createElement('div');
18941
+ toast.className = `codelab-toast codelab-toast--${kind === 'error' ? 'error' : 'info'}`;
18942
+ const icon = kind === 'error' ? (CL_ICONS.x || '⚠') : (CL_ICONS.externalLink || CL_ICONS.radio || '');
18943
+ toast.innerHTML = `
18944
+ <div class="codelab-toast__icon">${icon}</div>
18945
+ <div class="codelab-toast__body">
18946
+ <div class="codelab-toast__meta">${escapeHtml(message)}</div>
18947
+ </div>
18948
+ <button type="button" class="codelab-toast__close" aria-label="Dismiss notification">${CL_ICONS.x || '×'}</button>
18949
+ `;
18950
+ const closeBtn = toast.querySelector('.codelab-toast__close');
18951
+ const remove = () => {
18952
+ if (typeof toast.remove === 'function') toast.remove();
18953
+ else if (toast.parentNode) toast.parentNode.removeChild(toast);
18954
+ };
18955
+ if (closeBtn) closeBtn.addEventListener('click', remove);
18956
+ toastHost.appendChild(toast);
18957
+ setTimeout(remove, 5000);
18958
+ }
18959
+
18775
18960
  _registerPreviewServiceWorker() {
18776
18961
  if (typeof navigator === 'undefined' || !navigator.serviceWorker || typeof navigator.serviceWorker.register !== 'function') return;
18777
18962
  const url = (this.options && this.options.previewSwUrl) || 'preview-sw.js';
@@ -18862,9 +19047,53 @@ declare module 'bun:sqlite' {
18862
19047
  _previewGo(urlOrPath) {
18863
19048
  let url = String(urlOrPath || '').trim();
18864
19049
  if (!url) return Promise.resolve();
19050
+
19051
+ const loopbackPort = this.previewState.port || this._firstListeningPort() || 3000;
19052
+ const localHostRe = /^(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(:\d+)?(\/.*)?$/i;
19053
+
19054
+ // Normalize the input into an absolute URL.
18865
19055
  if (!/^https?:\/\//i.test(url)) {
18866
- url = `http://127.0.0.1:${this.previewState.port || this._firstListeningPort() || 3000}${url.startsWith('/') ? '' : '/'}${url}`;
19056
+ if (localHostRe.test(url)) {
19057
+ url = `http://${url}`;
19058
+ } else if (/^[a-z0-9-]+(\.[a-z0-9-]+)+(:\d+)?([/?#].*)?$/i.test(url)) {
19059
+ // Bare public domain, e.g. "google.com" or "example.com/path".
19060
+ url = `https://${url}`;
19061
+ } else {
19062
+ url = `http://127.0.0.1:${loopbackPort}${url.startsWith('/') ? '' : '/'}${url}`;
19063
+ }
19064
+ }
19065
+
19066
+ // Public (non-loopback) URLs cannot be served by the virtual loopback Service
19067
+ // Worker, so open them in a real browser tab instead of the in-browser frame.
19068
+ let isExternal = false;
19069
+ try {
19070
+ const u = new URL(url);
19071
+ const host = (u.hostname || '').toLowerCase();
19072
+ isExternal = !(host === 'localhost' || host === '127.0.0.1' || host === '0.0.0.0' || host === '::1' || host === '[::1]');
19073
+ } catch (_) { isExternal = false; }
19074
+
19075
+ if (isExternal) {
19076
+ let opened = false;
19077
+ if (typeof window !== 'undefined' && typeof window.open === 'function') {
19078
+ try {
19079
+ const win = window.open(url, '_blank');
19080
+ if (win) {
19081
+ try { win.opener = null; } catch (_) {}
19082
+ opened = true;
19083
+ }
19084
+ } catch (_) { opened = false; }
19085
+ }
19086
+ if (typeof this._showToast === 'function') {
19087
+ this._showToast(
19088
+ opened ? `Opened ${url} in a new tab` : `Could not open ${url} — allow pop-ups and try again`,
19089
+ opened ? 'info' : 'error'
19090
+ );
19091
+ }
19092
+ const inputEl = this.container.querySelector('#cl-preview-url-input');
19093
+ if (inputEl) inputEl.value = this.previewState.url || inputEl.value;
19094
+ return Promise.resolve();
18867
19095
  }
19096
+
18868
19097
  let port = this.previewState.port;
18869
19098
  let path = '/';
18870
19099
  try {
@@ -18974,7 +19203,7 @@ declare module 'bun:sqlite' {
18974
19203
  <button type="button" class="codelab-preview-btn" data-cl-action="preview-reload" title="Reload">${CL_ICONS.refresh || '⟳'}</button>
18975
19204
  </div>
18976
19205
  <select class="codelab-preview-port-select" data-cl-action="preview-port-change" aria-label="Preview port">${portOptions}</select>
18977
- <input type="text" class="codelab-preview-url-input" id="cl-preview-url-input" value="${escapeHtml(this.previewState.url)}" placeholder="http://127.0.0.1:3000/" aria-label="Preview URL" />
19206
+ <input type="text" class="codelab-preview-url-input" id="cl-preview-url-input" value="${escapeHtml(this.previewState.url)}" placeholder="127.0.0.1:3000/ or https://example.com" aria-label="Preview URL" title="Localhost/virtual ports load in-frame; public URLs open in a new tab" />
18978
19207
  <div class="codelab-preview-modes">
18979
19208
  <button type="button" class="codelab-preview-btn ${this.previewState.frameMode === 'desktop' ? 'active' : ''}" data-cl-action="preview-mode" data-mode="desktop" title="Desktop">${CL_ICONS.monitor || '▭'}</button>
18980
19209
  <button type="button" class="codelab-preview-btn ${this.previewState.frameMode === 'tablet' ? 'active' : ''}" data-cl-action="preview-mode" data-mode="tablet" title="Tablet">${CL_ICONS.tablet || '▢'}</button>
@@ -19593,6 +19822,11 @@ declare module 'bun:sqlite' {
19593
19822
  this._previewGo(previewInput.value);
19594
19823
  return;
19595
19824
  }
19825
+ if (e.key === 'Escape' && this.folderSwitcherOpen) {
19826
+ this.folderSwitcherOpen = false;
19827
+ this._renderBreadcrumbs();
19828
+ return;
19829
+ }
19596
19830
  if (e.key === 'F1' || ((e.metaKey || e.ctrlKey) && e.shiftKey && keyLower === 'p')) {
19597
19831
  e.preventDefault();
19598
19832
  this.openCommandPalette('commands');
@@ -19793,12 +20027,39 @@ declare module 'bun:sqlite' {
19793
20027
  return;
19794
20028
  }
19795
20029
 
20030
+ const fsToggle = e.target.closest('[data-cl-action="toggle-folder-switcher"]');
20031
+ if (fsToggle) {
20032
+ e.stopPropagation();
20033
+ this.folderSwitcherOpen = !this.folderSwitcherOpen;
20034
+ this._renderBreadcrumbs();
20035
+ return;
20036
+ }
20037
+
20038
+ const fsOption = e.target.closest('[data-cl-folder-option]');
20039
+ if (fsOption) {
20040
+ e.stopPropagation();
20041
+ const scopeVal = fsOption.dataset.clFolderOption || '';
20042
+ this.explorerFolder = scopeVal;
20043
+ if (scopeVal) this.collapsedFolders.delete(scopeVal);
20044
+ this.folderSwitcherOpen = false;
20045
+ this._renderFileLists();
20046
+ this._renderBreadcrumbs();
20047
+ return;
20048
+ }
20049
+
20050
+ if (this.folderSwitcherOpen && !e.target.closest('.codelab-folder-switcher')) {
20051
+ this.folderSwitcherOpen = false;
20052
+ this._renderBreadcrumbs();
20053
+ }
20054
+
19796
20055
  const bcFolder = e.target.closest('[data-cl-breadcrumb-folder]');
19797
20056
  if (bcFolder) {
19798
20057
  const folder = bcFolder.dataset.clBreadcrumbFolder;
19799
20058
  if (folder) {
19800
20059
  this.collapsedFolders.delete(folder);
20060
+ this.explorerFolder = folder;
19801
20061
  this._renderFileLists();
20062
+ this._renderBreadcrumbs();
19802
20063
  }
19803
20064
  return;
19804
20065
  }
@@ -19933,10 +20194,10 @@ declare module 'bun:sqlite' {
19933
20194
  this.isCreatingFile = true;
19934
20195
  this._renderFileLists();
19935
20196
  } else if (action === 'new-file-root') {
19936
- this.creatingItem = { type: 'file', parentFolder: '' };
20197
+ this.creatingItem = { type: 'file', parentFolder: this.explorerFolder || '' };
19937
20198
  this._renderFileLists();
19938
20199
  } else if (action === 'new-folder-root') {
19939
- this.creatingItem = { type: 'folder', parentFolder: '' };
20200
+ this.creatingItem = { type: 'folder', parentFolder: this.explorerFolder || '' };
19940
20201
  this._renderFileLists();
19941
20202
  } else if (action === 'new-file-folder') {
19942
20203
  const folder = actionBtn.dataset.clFolder || '';
package/dist/shell.esm.js CHANGED
@@ -2004,6 +2004,10 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2004
2004
  }
2005
2005
 
2006
2006
  async function cloneGitHubRepository(repoInput, vfs, options = {}) {
2007
+ const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null;
2008
+ if (onProgress) {
2009
+ onProgress({ phase: 'connecting', message: `Connecting to repository '${repoInput}'...` });
2010
+ }
2007
2011
  const parsed = parseGitHubRepoUrl(repoInput);
2008
2012
  if (!parsed) {
2009
2013
  throw new Error(`fatal: repository '${repoInput}' does not exist or is not a valid GitHub repository URL`);
@@ -2027,6 +2031,10 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2027
2031
  let rawTreeEntries = null;
2028
2032
  let repoNotFound = false;
2029
2033
 
2034
+ if (onProgress) {
2035
+ onProgress({ phase: 'metadata', message: `Fetching repository metadata for ${owner}/${repo}...` });
2036
+ }
2037
+
2030
2038
  // Strategy A: GitHub REST API (with automatic fallback if rate-limited)
2031
2039
  try {
2032
2040
  if (!resolvedBranch) {
@@ -2131,6 +2139,11 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2131
2139
 
2132
2140
  filtered.sort((a, b) => a.priority - b.priority || a.destPath.localeCompare(b.destPath));
2133
2141
  const selectedFiles = filtered.slice(0, maxFiles);
2142
+ const totalToDownload = selectedFiles.length;
2143
+
2144
+ if (onProgress) {
2145
+ onProgress({ phase: 'downloading', message: `Downloading files (0/${totalToDownload})...`, loaded: 0, total: totalToDownload });
2146
+ }
2134
2147
 
2135
2148
  if (!vfs.existsSync(targetDir)) {
2136
2149
  vfs.mkdirSync(targetDir, { recursive: true });
@@ -2176,6 +2189,9 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2176
2189
  headSnapshot[entry.destPath] = text;
2177
2190
  filesWritten++;
2178
2191
  totalBytes += text.length;
2192
+ if (onProgress) {
2193
+ onProgress({ phase: 'downloading', message: `Downloading files (${filesWritten}/${totalToDownload}): ${entry.destPath}`, loaded: filesWritten, total: totalToDownload });
2194
+ }
2179
2195
  if (typeof options.onFile === 'function') {
2180
2196
  options.onFile(absPath, text, entry.destPath);
2181
2197
  }
@@ -2184,6 +2200,10 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2184
2200
  );
2185
2201
  }
2186
2202
 
2203
+ if (onProgress) {
2204
+ onProgress({ phase: 'mounting', message: `Mounting files and writing Git metadata into ${targetDir}...`, loaded: filesWritten, total: totalToDownload });
2205
+ }
2206
+
2187
2207
  // Write .git metadata inside targetDir
2188
2208
  const gitDir = PosixPath.join(targetDir, '.git');
2189
2209
  if (!vfs.existsSync(gitDir)) {
@@ -2232,6 +2252,10 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
2232
2252
  ];
2233
2253
  }
2234
2254
 
2255
+ if (onProgress) {
2256
+ onProgress({ phase: 'ready', message: `Repository cloned successfully (${filesWritten} files).`, loaded: filesWritten, total: totalToDownload });
2257
+ }
2258
+
2235
2259
  return {
2236
2260
  owner,
2237
2261
  repo,
@@ -4431,12 +4455,37 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
4431
4455
  dirDisplayName = parsed.repo;
4432
4456
  }
4433
4457
 
4458
+ // Stream clone progress to the terminal as it happens (no end-of-run buffering).
4459
+ const canStream = typeof ctx.onStdout === 'function';
4460
+ const streamLine = (text) => { if (canStream && text) ctx.onStdout(text); };
4461
+ streamLine(`Cloning into '${dirDisplayName}'...\n`);
4462
+ let enumeratedEmitted = false;
4463
+ let lastProgressPct = -1;
4464
+
4434
4465
  try {
4435
4466
  const result = await cloneGitHubRepository(repoArg, ctx.vfs, {
4436
4467
  targetDir,
4437
4468
  branch: branchOpt,
4438
4469
  fetchImpl: ctx.shell && ctx.shell.options ? ctx.shell.options.fetchImpl : undefined,
4439
- onFile: (absPath) => ctx.emitMutation('create', absPath)
4470
+ onFile: (absPath) => ctx.emitMutation('create', absPath),
4471
+ onProgress: (ev) => {
4472
+ if (!ev) return;
4473
+ if (ev.phase === 'downloading' && !enumeratedEmitted && typeof ev.total === 'number' && ev.total > 0) {
4474
+ enumeratedEmitted = true;
4475
+ streamLine(`remote: Enumerating objects: ${ev.total}, done.\n`);
4476
+ streamLine(`remote: Counting objects: 100% (${ev.total}/${ev.total}), done.\n`);
4477
+ }
4478
+ if (ev.phase === 'downloading' && typeof ev.total === 'number' && ev.total > 0 && typeof ev.loaded === 'number' && ev.loaded < ev.total) {
4479
+ const pct = Math.min(100, Math.max(0, Math.floor((ev.loaded / ev.total) * 100)));
4480
+ if (pct >= lastProgressPct + 10) {
4481
+ lastProgressPct = pct;
4482
+ streamLine(`Receiving objects: ${pct}% (${ev.loaded}/${ev.total})\n`);
4483
+ }
4484
+ }
4485
+ if (ev.phase === 'mounting') {
4486
+ streamLine(`Resolving deltas: 100% (${ev.total || 0}/${ev.total || 0}), done.\n`);
4487
+ }
4488
+ }
4440
4489
  });
4441
4490
 
4442
4491
  gitState.branch = result.branch;
@@ -4450,6 +4499,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
4450
4499
 
4451
4500
  const count = Math.max(1, result.filesWritten);
4452
4501
  const kb = Math.max(0.1, result.totalBytes / 1024).toFixed(1);
4502
+ streamLine(`Receiving objects: 100% (${count}/${count}), ${kb} KiB, done.\n`);
4453
4503
  const stdout =
4454
4504
  `Cloning into '${dirDisplayName}'...\n` +
4455
4505
  `remote: Enumerating objects: ${count}, done.\n` +
@@ -4458,6 +4508,7 @@ const _root = typeof globalThis !== 'undefined' ? globalThis : typeof window !==
4458
4508
  return { code: 0, stdout, stderr: '' };
4459
4509
  } catch (err) {
4460
4510
  const msg = err && err.message ? err.message : String(err);
4511
+ if (canStream) streamLine(msg.endsWith('\n') ? msg : msg + '\n');
4461
4512
  return { code: 128, stdout: '', stderr: (msg.endsWith('\n') ? msg : msg + '\n') };
4462
4513
  }
4463
4514
  }