@innovatorved/code-lab 0.5.0 → 0.6.1

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.
Files changed (76) hide show
  1. package/ARCHITECTURE.md +3 -3
  2. package/CHANGELOG.md +23 -0
  3. package/README.md +3 -3
  4. package/dist/code-lab-sql.css +87 -64
  5. package/dist/code-lab-sql.esm.js +109 -86
  6. package/dist/code-lab-sql.umd.js +110 -87
  7. package/dist/code-lab.css +32 -7273
  8. package/dist/code-lab.d.ts +1 -1
  9. package/dist/code-lab.esm.js +4966 -74622
  10. package/dist/code-lab.js +4974 -74631
  11. package/dist/code-lab.umd.js +4974 -74631
  12. package/dist/extensions/cpp.d.ts +2 -2
  13. package/dist/extensions/cpp.esm.js +1788 -14707
  14. package/dist/extensions/cpp.js +1788 -14707
  15. package/dist/extensions/guided-lab.esm.js +2938 -16127
  16. package/dist/extensions/guided-lab.js +2938 -16127
  17. package/dist/extensions/python.d.ts +2 -2
  18. package/dist/extensions/python.esm.js +1769 -14701
  19. package/dist/extensions/python.js +1769 -14701
  20. package/dist/index.d.ts +1 -1
  21. package/dist/packages/sql/src/styles.d.ts +1 -1
  22. package/dist/packages/ui/src/settings-dialog.d.ts +2 -0
  23. package/dist/preview-sw.js +4 -188
  24. package/dist/runtime.esm.js +109 -10284
  25. package/dist/runtime.js +107 -10284
  26. package/dist/schemas.d.ts +2 -2
  27. package/dist/schemas.esm.js +2938 -16127
  28. package/dist/schemas.js +2941 -16130
  29. package/dist/scm.d.ts +221 -20
  30. package/dist/shell.esm.js +811 -10002
  31. package/dist/shell.js +811 -10002
  32. package/dist/storage.d.ts +9 -0
  33. package/dist/terminal.esm.js +20 -1347
  34. package/dist/terminal.js +20 -1347
  35. package/dist/workbench/command-palette.d.ts +16 -1
  36. package/dist/workbench/diff-editor.d.ts +27 -1
  37. package/dist/workbench/icons.d.ts +6 -2
  38. package/dist/workbench/index.d.ts +33 -1
  39. package/dist/workbench/intellisense.d.ts +194 -0
  40. package/dist/workbench/styles.d.ts +1 -1
  41. package/dist/workbench/xterm-adapter.d.ts +122 -0
  42. package/package.json +7 -1
  43. package/packages/commands/package.json +1 -1
  44. package/packages/core/package.json +1 -1
  45. package/packages/editor/package.json +1 -1
  46. package/packages/fs/package.json +1 -1
  47. package/packages/preview/package.json +1 -1
  48. package/packages/runtime/package.json +1 -1
  49. package/packages/settings/package.json +1 -1
  50. package/packages/sql/package.json +1 -1
  51. package/packages/sql/src/styles.ts +87 -64
  52. package/packages/terminal/package.json +1 -1
  53. package/packages/ui/package.json +1 -1
  54. package/packages/ui/src/observability.ts +12 -14
  55. package/packages/ui/src/settings-dialog.ts +383 -47
  56. package/packages/ui/src/themes.ts +89 -23
  57. package/src/code-lab.css +1883 -578
  58. package/src/extensions/cpp.ts +304 -38
  59. package/src/extensions/python.ts +342 -43
  60. package/src/index.ts +1 -1
  61. package/src/runtime.ts +272 -43
  62. package/src/schemas.ts +2 -2
  63. package/src/scm.ts +1467 -92
  64. package/src/shell.ts +1075 -93
  65. package/src/storage.ts +66 -3
  66. package/src/terminal.ts +148 -12
  67. package/src/workbench/command-palette.ts +289 -48
  68. package/src/workbench/diff-editor.ts +244 -78
  69. package/src/workbench/drawer.ts +5 -5
  70. package/src/workbench/icons.ts +250 -53
  71. package/src/workbench/index.ts +7 -1
  72. package/src/workbench/intellisense.ts +1871 -0
  73. package/src/workbench/styles.ts +58 -54
  74. package/src/workbench/toolbar.ts +1 -1
  75. package/src/workbench/xterm-adapter.ts +1571 -0
  76. package/src/workbench.ts +1699 -324
package/src/workbench.ts CHANGED
@@ -83,7 +83,7 @@
83
83
 
84
84
  // The bundler rewrites this literal from package.json at build time. Keeping
85
85
  // the fallback in sync lets tests require src/workbench.js directly.
86
- const CODELAB_VERSION = '0.5.0';
86
+ const CODELAB_VERSION = '0.6.1';
87
87
 
88
88
  // Ambient TypeScript declarations for Node.js built-ins inside Monaco
89
89
  const NODE_AMBIENT_DTS = `
@@ -1019,36 +1019,37 @@ declare module 'bun:sqlite' {
1019
1019
  reject(new Error('Monaco failed to initialize'));
1020
1020
  return;
1021
1021
  }
1022
- // Define custom themes synced with Ved Gupta Monochrome Neutral Design System (Geist)
1022
+ // Define custom themes synced with Ved Gupta Monochrome Charcoal Ink & Warm Paper Design System (Geist)
1023
1023
  m.editor.defineTheme('codelab-dark', {
1024
1024
  base: 'vs-dark',
1025
1025
  inherit: true,
1026
1026
  rules: [
1027
- { token: 'comment', foreground: '666666', fontStyle: 'italic' },
1028
- { token: 'keyword', foreground: 'ff7b72' },
1029
- { token: 'string', foreground: 'a5d6ff' },
1030
- { token: 'number', foreground: '79c0ff' },
1031
- { token: 'type', foreground: 'ffa657' }
1027
+ { token: 'comment', foreground: '8e8e97', fontStyle: 'italic' },
1028
+ { token: 'keyword', foreground: 'f87171' },
1029
+ { token: 'string', foreground: '86efac' },
1030
+ { token: 'number', foreground: 'fcd34d' },
1031
+ { token: 'type', foreground: 'fb923c' },
1032
+ { token: 'function', foreground: 'c084fc' }
1032
1033
  ],
1033
1034
  colors: {
1034
- 'editor.background': '#000000',
1035
- 'editor.foreground': '#f2f2f2',
1036
- 'editorGutter.background': '#000000',
1037
- 'editorLineNumber.foreground': '#525252',
1038
- 'editorLineNumber.activeForeground': '#ffffff',
1039
- 'editor.lineHighlightBackground': '#0a0a0a',
1040
- 'editor.lineHighlightBorder': '#171717',
1041
- 'editor.selectionBackground': '#262626',
1042
- 'editor.inactiveSelectionBackground': '#171717',
1043
- 'editorCursor.foreground': '#ffffff',
1044
- 'editorIndentGuide.background1': '#171717',
1045
- 'editorIndentGuide.activeBackground1': '#262626',
1046
- 'editorWidget.background': '#0a0a0a',
1047
- 'editorWidget.border': '#262626',
1048
- 'editorHoverWidget.background': '#0a0a0a',
1049
- 'editorHoverWidget.border': '#262626',
1050
- 'scrollbarSlider.background': '#26262680',
1051
- 'scrollbarSlider.hoverBackground': '#404040aa'
1035
+ 'editor.background': '#0f0f10',
1036
+ 'editor.foreground': '#f4f4f5',
1037
+ 'editorGutter.background': '#0f0f10',
1038
+ 'editorLineNumber.foreground': '#6e6e77',
1039
+ 'editorLineNumber.activeForeground': '#f4f4f5',
1040
+ 'editor.lineHighlightBackground': '#18181a99',
1041
+ 'editor.lineHighlightBorder': '#00000000',
1042
+ 'editor.selectionBackground': '#28282b',
1043
+ 'editor.inactiveSelectionBackground': '#1f1f22',
1044
+ 'editorCursor.foreground': '#f4f4f5',
1045
+ 'editorIndentGuide.background1': '#27272a80',
1046
+ 'editorIndentGuide.activeBackground1': '#3a3a3e',
1047
+ 'editorWidget.background': '#18181a',
1048
+ 'editorWidget.border': '#27272a',
1049
+ 'editorHoverWidget.background': '#18181a',
1050
+ 'editorHoverWidget.border': '#27272a',
1051
+ 'scrollbarSlider.background': '#3a3a3e66',
1052
+ 'scrollbarSlider.hoverBackground': '#52525b99'
1052
1053
  }
1053
1054
  });
1054
1055
 
@@ -1056,47 +1057,62 @@ declare module 'bun:sqlite' {
1056
1057
  base: 'vs',
1057
1058
  inherit: true,
1058
1059
  rules: [
1059
- { token: 'comment', foreground: '666666', fontStyle: 'italic' }
1060
+ { token: 'comment', foreground: '6e6a64', fontStyle: 'italic' },
1061
+ { token: 'keyword', foreground: 'c2410c' },
1062
+ { token: 'string', foreground: '067647' },
1063
+ { token: 'number', foreground: 'b54708' },
1064
+ { token: 'type', foreground: '9a3412' },
1065
+ { token: 'function', foreground: '6d28d9' }
1060
1066
  ],
1061
1067
  colors: {
1062
1068
  'editor.background': '#ffffff',
1063
- 'editor.foreground': '#0a0a0a',
1069
+ 'editor.foreground': '#18181b',
1064
1070
  'editorGutter.background': '#ffffff',
1065
- 'editorLineNumber.foreground': '#8f8f8f',
1066
- 'editorLineNumber.activeForeground': '#0a0a0a',
1067
- 'editor.lineHighlightBackground': '#fafafa',
1068
- 'editor.lineHighlightBorder': '#f5f5f5',
1069
- 'editor.selectionBackground': '#e5e5e5',
1070
- 'editor.inactiveSelectionBackground': '#f5f5f5',
1071
- 'editorCursor.foreground': '#000000',
1072
- 'editorIndentGuide.background1': '#f0f0f0',
1073
- 'editorIndentGuide.activeBackground1': '#d4d4d4',
1074
- 'editorWidget.background': '#fafafa',
1075
- 'editorWidget.border': '#e5e5e5',
1076
- 'editorHoverWidget.background': '#fafafa',
1077
- 'editorHoverWidget.border': '#e5e5e5'
1071
+ 'editorLineNumber.foreground': '#8a8680',
1072
+ 'editorLineNumber.activeForeground': '#18181b',
1073
+ 'editor.lineHighlightBackground': '#f7f7f5',
1074
+ 'editor.lineHighlightBorder': '#00000000',
1075
+ 'editor.selectionBackground': '#e6e4df',
1076
+ 'editor.inactiveSelectionBackground': '#f1f1ee',
1077
+ 'editorCursor.foreground': '#18181b',
1078
+ 'editorIndentGuide.background1': '#e6e4df',
1079
+ 'editorIndentGuide.activeBackground1': '#d3d0c9',
1080
+ 'editorWidget.background': '#f7f7f5',
1081
+ 'editorWidget.border': '#e6e4df',
1082
+ 'editorHoverWidget.background': '#f7f7f5',
1083
+ 'editorHoverWidget.border': '#e6e4df'
1078
1084
  }
1079
1085
  });
1080
1086
 
1081
- // Configure TS/JS defaults & ambient Node types
1087
+ // Configure TS/JS defaults, Modern themes & ambient Node types
1088
+ const wbComp = (root && root.CodeLabWorkbenchComponents) ||
1089
+ (typeof globalThis !== 'undefined' && globalThis.CodeLabWorkbenchComponents) ||
1090
+ null;
1091
+ if (wbComp && typeof wbComp.registerCodeLabMonacoThemes === 'function') {
1092
+ wbComp.registerCodeLabMonacoThemes(m);
1093
+ }
1082
1094
  if (m.languages && m.languages.typescript) {
1083
1095
  const tsDefaults = m.languages.typescript.typescriptDefaults;
1084
1096
  const jsDefaults = m.languages.typescript.javascriptDefaults;
1085
1097
  const compilerOpts = {
1086
- target: m.languages.typescript.ScriptTarget.ES2020,
1087
- module: m.languages.typescript.ModuleKind.CommonJS,
1098
+ target: m.languages.typescript.ScriptTarget.ESNext || m.languages.typescript.ScriptTarget.ES2020,
1099
+ module: m.languages.typescript.ModuleKind.ESNext || m.languages.typescript.ModuleKind.CommonJS,
1088
1100
  moduleResolution: m.languages.typescript.ModuleResolutionKind.NodeJs,
1089
1101
  allowNonTsExtensions: true,
1090
1102
  allowJs: true,
1091
1103
  checkJs: false,
1092
1104
  strict: false,
1093
1105
  noEmit: true,
1094
- esModuleInterop: true
1106
+ esModuleInterop: true,
1107
+ allowSyntheticDefaultImports: true,
1108
+ resolveJsonModule: true
1095
1109
  };
1096
1110
  tsDefaults.setCompilerOptions(compilerOpts);
1097
1111
  jsDefaults.setCompilerOptions(compilerOpts);
1112
+ if (typeof tsDefaults.setEagerModelSync === 'function') tsDefaults.setEagerModelSync(true);
1113
+ if (typeof jsDefaults.setEagerModelSync === 'function') jsDefaults.setEagerModelSync(true);
1098
1114
  tsDefaults.setDiagnosticsOptions({ noSemanticValidation: false, noSyntaxValidation: false });
1099
- jsDefaults.setDiagnosticsOptions({ noSemanticValidation: true, noSyntaxValidation: false });
1115
+ jsDefaults.setDiagnosticsOptions({ noSemanticValidation: false, noSyntaxValidation: false });
1100
1116
  tsDefaults.addExtraLib(NODE_AMBIENT_DTS, 'file:///node-ambient.d.ts');
1101
1117
  jsDefaults.addExtraLib(NODE_AMBIENT_DTS, 'file:///node-ambient.d.ts');
1102
1118
  }
@@ -1269,7 +1285,12 @@ int main() {
1269
1285
  'test.js': `'use strict';\nconst { describe, it } = require('node:test');\nconst assert = require('node:assert/strict');\nconst { solve } = require('./index.js');\n\ndescribe('Standalone Sandbox', () => {\n it('returns the input payload', () => {\n assert.deepEqual(solve({ a: 1 }), { a: 1 });\n });\n});\n`
1270
1286
  };
1271
1287
 
1272
- const CL_ICONS = {
1288
+ const _wbComponents = (typeof CodeLabWorkbenchComponents !== 'undefined' && CodeLabWorkbenchComponents) ||
1289
+ (root && root.CodeLabWorkbenchComponents) ||
1290
+ (typeof globalThis !== 'undefined' && globalThis.CodeLabWorkbenchComponents) ||
1291
+ {};
1292
+
1293
+ const CL_ICONS = Object.assign({
1273
1294
  arrowLeft: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>',
1274
1295
  target: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/></svg>',
1275
1296
  code: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',
@@ -1320,8 +1341,9 @@ int main() {
1320
1341
  panelBottom: '<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="3" y1="15" x2="21" y2="15"/></svg>',
1321
1342
  chevronUp: '<svg aria-hidden="true" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"/></svg>',
1322
1343
  collapseAll: '<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="16" rx="2"/><line x1="8" y1="12" x2="16" y2="12"/></svg>',
1323
- close: '<svg aria-hidden="true" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>'
1324
- };
1344
+ close: '<svg aria-hidden="true" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',
1345
+ splitHorizontal: '<svg aria-hidden="true" width="14" height="14" viewBox="0 0 16 16" fill="currentColor"><path d="M14 1H3L2 2v11l1 1h11l1-1V2l-1-1zM8 13H3V2h5v11zm6 0H9V2h5v11z"/></svg>'
1346
+ }, (_wbComponents && _wbComponents.CL_ICONS) || {});
1325
1347
 
1326
1348
  let _workbenchInstanceCounter = 0;
1327
1349
  const _fallbackStorage = new Map();
@@ -1551,13 +1573,13 @@ int main() {
1551
1573
  ...(options.guided || {}),
1552
1574
  ...(options.starterFiles ? { starterFiles: options.starterFiles } : {}),
1553
1575
  ...(options.tsStarterFiles ? { tsStarterFiles: options.tsStarterFiles } : {}),
1554
- ...((options.tsSolutionFiles || options.tsFiles) ? { tsSolutionFiles: options.tsSolutionFiles || options.tsFiles } : {}),
1576
+ ...((options.tsSolutionFiles || options.tsFiles || options.filesTs) ? { tsSolutionFiles: options.tsSolutionFiles || options.tsFiles || options.filesTs } : {}),
1555
1577
  ...(options.cppStarterFiles ? { cppStarterFiles: options.cppStarterFiles } : {}),
1556
- ...((options.cppSolutionFiles || options.cppFiles) ? { cppSolutionFiles: options.cppSolutionFiles || options.cppFiles } : {}),
1578
+ ...((options.cppSolutionFiles || options.cppFiles || options.filesCpp) ? { cppSolutionFiles: options.cppSolutionFiles || options.cppFiles || options.filesCpp } : {}),
1557
1579
  ...(options.pyStarterFiles ? { pyStarterFiles: options.pyStarterFiles } : {}),
1558
- ...((options.pySolutionFiles || options.pyFiles) ? { pySolutionFiles: options.pySolutionFiles || options.pyFiles } : {}),
1580
+ ...((options.pySolutionFiles || options.pyFiles || options.filesPy) ? { pySolutionFiles: options.pySolutionFiles || options.pyFiles || options.filesPy } : {}),
1559
1581
  ...(options.sqlStarterFiles ? { sqlStarterFiles: options.sqlStarterFiles } : {}),
1560
- ...((options.sqlSolutionFiles || options.sqlFiles) ? { sqlSolutionFiles: options.sqlSolutionFiles || options.sqlFiles } : {})
1582
+ ...((options.sqlSolutionFiles || options.sqlFiles || options.filesSql) ? { sqlSolutionFiles: options.sqlSolutionFiles || options.sqlFiles || options.filesSql } : {})
1561
1583
  };
1562
1584
  this.steps = options.steps || this.guidedConfig?.steps || [];
1563
1585
  this.hasGuidedLab = Boolean(
@@ -1684,7 +1706,9 @@ int main() {
1684
1706
  : (typeof this.savedState?.sidebarVisible === 'boolean' ? this.savedState.sidebarVisible : true);
1685
1707
  this.panelVisible = typeof options.panelVisible === 'boolean'
1686
1708
  ? options.panelVisible
1687
- : (typeof this.savedState?.panelVisible === 'boolean' ? this.savedState.panelVisible : true);
1709
+ : (typeof options.drawerCollapsed === 'boolean'
1710
+ ? !options.drawerCollapsed
1711
+ : (typeof this.savedState?.panelVisible === 'boolean' ? this.savedState.panelVisible : true));
1688
1712
  this.drawerCollapsed = !this.panelVisible;
1689
1713
  this.panelHeight = (typeof this.savedState?.panelHeight === 'number' && this.savedState.panelHeight >= 100)
1690
1714
  ? this.savedState.panelHeight
@@ -2311,9 +2335,11 @@ int main() {
2311
2335
  if (typeof createPosixShell === 'function') {
2312
2336
  try {
2313
2337
  this.shell = createPosixShell({
2338
+ instanceId: this.instanceId,
2314
2339
  cwd: this.cwd,
2315
2340
  files: this.files,
2316
2341
  portTable: this.portTable,
2342
+ onRequestStdin: (promptText) => this._requestInteractiveTerminalStdin(promptText),
2317
2343
  env: {
2318
2344
  PWD: this.cwd || '/workspace',
2319
2345
  TERM: 'xterm-256color',
@@ -2970,12 +2996,43 @@ int main() {
2970
2996
  }
2971
2997
  }
2972
2998
 
2999
+ _ensureSystemColorSchemeListener() {
3000
+ if (this._systemSchemeMedia || typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;
3001
+ try {
3002
+ const mql = window.matchMedia('(prefers-color-scheme: dark)');
3003
+ if (!mql) return;
3004
+ const onChange = () => {
3005
+ if (this._destroyed) return;
3006
+ if (this.themeOption === 'auto') {
3007
+ this.setTheme('auto');
3008
+ }
3009
+ };
3010
+ if (typeof mql.addEventListener === 'function') {
3011
+ mql.addEventListener('change', onChange);
3012
+ this._systemSchemeCleanup = () => {
3013
+ try { mql.removeEventListener('change', onChange); } catch (_err) { void _err; }
3014
+ };
3015
+ } else if (typeof mql.addListener === 'function') {
3016
+ mql.addListener(onChange);
3017
+ this._systemSchemeCleanup = () => {
3018
+ try { mql.removeListener(onChange); } catch (_err) { void _err; }
3019
+ };
3020
+ }
3021
+ this._systemSchemeMedia = mql;
3022
+ } catch (_err) {
3023
+ void _err;
3024
+ }
3025
+ }
3026
+
2973
3027
  setTheme(nextTheme) {
2974
3028
  const normalized = (nextTheme === 'light' || nextTheme === 'dark' || nextTheme === 'high-contrast' || nextTheme === 'auto')
2975
3029
  ? nextTheme
2976
3030
  : 'dark';
2977
3031
  this.themeOption = normalized;
2978
3032
  this.theme = normalized;
3033
+ if (normalized === 'auto') {
3034
+ this._ensureSystemColorSchemeListener();
3035
+ }
2979
3036
  const resolved = this._resolvedTheme();
2980
3037
  if (this.themes && typeof this.themes.setTheme === 'function' && !this._applyingThemeFromService) {
2981
3038
  try {
@@ -2999,7 +3056,11 @@ int main() {
2999
3056
  }
3000
3057
  if (shellEl) {
3001
3058
  shellEl.setAttribute('data-cl-theme', resolved);
3002
- if (typeof document !== 'undefined' && document.documentElement && typeof document.documentElement.setAttribute === 'function') {
3059
+ const shouldSyncRootHtml = Boolean(
3060
+ (this.options && (this.options.fullbleed || this.options.syncDocumentTheme)) ||
3061
+ (typeof document !== 'undefined' && document.documentElement && typeof document.documentElement.hasAttribute === 'function' && document.documentElement.hasAttribute('data-theme'))
3062
+ );
3063
+ if (shouldSyncRootHtml && typeof document !== 'undefined' && document.documentElement && typeof document.documentElement.setAttribute === 'function') {
3003
3064
  try {
3004
3065
  document.documentElement.setAttribute('data-theme', resolved);
3005
3066
  } catch (_err) {
@@ -3010,12 +3071,12 @@ int main() {
3010
3071
  if (typeof shellEl.removeAttribute === 'function') shellEl.removeAttribute('data-theme');
3011
3072
  } else {
3012
3073
  shellEl.setAttribute('data-theme', normalized);
3013
- if (this.themes && typeof this.themes.applyToElement === 'function' && shellEl.style && typeof shellEl.style.setProperty === 'function') {
3014
- try {
3015
- this.themes.applyToElement(shellEl);
3016
- } catch (err) {
3017
- this.logger.debug('themes.applyToElement failed.', err);
3018
- }
3074
+ }
3075
+ if (this.themes && typeof this.themes.applyToElement === 'function' && shellEl.style && typeof shellEl.style.setProperty === 'function') {
3076
+ try {
3077
+ this.themes.applyToElement(shellEl);
3078
+ } catch (err) {
3079
+ this.logger.debug('themes.applyToElement failed.', err);
3019
3080
  }
3020
3081
  }
3021
3082
  if (shellEl.style) {
@@ -3035,17 +3096,26 @@ int main() {
3035
3096
  }
3036
3097
  }
3037
3098
  if (this.monaco && this.monaco.editor && typeof this.monaco.editor.setTheme === 'function') {
3038
- const monacoTheme = resolved === 'light'
3039
- ? 'codelab-light'
3040
- : resolved === 'high-contrast'
3041
- ? 'codelab-hc-dark'
3042
- : 'codelab-dark';
3099
+ const monacoTheme = (_wbComponents && typeof _wbComponents.getMonacoThemeName === 'function')
3100
+ ? _wbComponents.getMonacoThemeName(resolved, this.monaco)
3101
+ : (resolved === 'light'
3102
+ ? 'codelab-light'
3103
+ : resolved === 'high-contrast'
3104
+ ? 'codelab-hc-dark'
3105
+ : 'codelab-dark');
3043
3106
  try {
3044
3107
  this.monaco.editor.setTheme(monacoTheme);
3045
3108
  } catch (err) {
3046
3109
  this.logger.debug('monaco.editor.setTheme failed.', err);
3047
3110
  }
3048
3111
  }
3112
+ if (this._xtermEngines instanceof Map) {
3113
+ for (const eng of this._xtermEngines.values()) {
3114
+ if (eng && typeof eng.setTheme === 'function') {
3115
+ try { eng.setTheme(resolved); } catch (_err) { void _err; }
3116
+ }
3117
+ }
3118
+ }
3049
3119
  if (this._sqlWorkbenchEditor && typeof this._sqlWorkbenchEditor.setTheme === 'function') {
3050
3120
  try {
3051
3121
  this._sqlWorkbenchEditor.setTheme(resolved === 'light' ? 'light' : 'dark');
@@ -3582,9 +3652,50 @@ int main() {
3582
3652
  }
3583
3653
  if (!this.activeFile && this.openTabs.length > 0) {
3584
3654
  this.activeFile = this._pickDefaultFile() || this.openTabs[0];
3585
- if (this.activeTab !== '__settings__') this.activeTab = this.activeFile;
3655
+ if (this.activeTab !== '__settings__' && this.activeTab !== '__welcome__') this.activeTab = this.activeFile;
3586
3656
  }
3587
3657
  this._syncFilesToShellVfs({ pruneExtraneous: forceHydrate });
3658
+ if (this.shell && this.shell.vfs && typeof this.shell.vfs.writeFileSync === 'function') {
3659
+ if (project.binaryFiles && typeof project.binaryFiles === 'object') {
3660
+ for (const [relBin, bytes] of Object.entries(project.binaryFiles)) {
3661
+ if (!relBin || !(bytes instanceof Uint8Array)) continue;
3662
+ try {
3663
+ const absBin = '/workspace/' + String(relBin).replace(/^\/+/, '');
3664
+ const parentBin = absBin.split('/').slice(0, -1).join('/');
3665
+ if (parentBin && typeof this.shell.vfs.mkdirSync === 'function') {
3666
+ this.shell.vfs.mkdirSync(parentBin, { recursive: true });
3667
+ }
3668
+ this.shell.vfs.writeFileSync(absBin, bytes);
3669
+ } catch (_err) { void _err; }
3670
+ }
3671
+ }
3672
+ if (project.gitFiles && typeof project.gitFiles === 'object') {
3673
+ for (const [relGit, bytes] of Object.entries(project.gitFiles)) {
3674
+ if (!relGit) continue;
3675
+ try {
3676
+ const absGit = '/workspace/.git/' + String(relGit).replace(/^(?:\.git\/|\/)+/, '');
3677
+ const parentGit = absGit.split('/').slice(0, -1).join('/');
3678
+ if (parentGit && typeof this.shell.vfs.mkdirSync === 'function') {
3679
+ this.shell.vfs.mkdirSync(parentGit, { recursive: true });
3680
+ }
3681
+ this.shell.vfs.writeFileSync(absGit, bytes instanceof Uint8Array ? bytes : String(bytes));
3682
+ } catch (_err) { void _err; }
3683
+ }
3684
+ }
3685
+ }
3686
+ if (project.gitMeta && typeof project.gitMeta === 'object' && typeof this._restoreSavedGitState === 'function') {
3687
+ this._restoreSavedGitState(project.gitMeta);
3688
+ } else if (project.gitFiles && root.CodeLabScm && typeof root.CodeLabScm.hydrateFromIsoGitRepo === 'function' && this.shell && this.shell.vfs) {
3689
+ const gs = this._getGitState();
3690
+ if (gs) {
3691
+ Promise.resolve(root.CodeLabScm.hydrateFromIsoGitRepo(this.shell.vfs, gs)).then((hydrated) => {
3692
+ if (hydrated && !this._destroyed) {
3693
+ if (this.activeSidebarView === 'scm') this._renderScmSidebar();
3694
+ this._updateStatusBar();
3695
+ }
3696
+ }).catch((_e) => { void _e; });
3697
+ }
3698
+ }
3588
3699
  this._buildSavedStateSnapshot({ flushFiles: true });
3589
3700
  this._syncAllModels();
3590
3701
  this._syncDotCodelabConfig();
@@ -3663,12 +3774,52 @@ int main() {
3663
3774
  const stateSnapshot = state;
3664
3775
  const targetLabId = this.labId;
3665
3776
  const targetTitle = this.title || this.labId;
3777
+ const binaryFilesSnapshot = {};
3778
+ const gitFilesSnapshot = {};
3779
+ if (this.shell && this.shell.vfs && typeof this.shell.vfs.readdirSync === 'function') {
3780
+ const collectRawDir = (dirPath, isGitTree) => {
3781
+ let entries = [];
3782
+ try { entries = this.shell.vfs.readdirSync(dirPath) || []; } catch (_e) { void _e; return; }
3783
+ for (const ent of entries) {
3784
+ const name = typeof ent === 'string' ? ent : (ent && ent.name ? ent.name : '');
3785
+ if (!name || name === '.' || name === '..' || name === 'node_modules') continue;
3786
+ const full = (dirPath === '/' ? '' : dirPath) + '/' + name;
3787
+ if (!isGitTree && name === '.git') {
3788
+ collectRawDir(full, true);
3789
+ continue;
3790
+ }
3791
+ let st = null;
3792
+ try { st = this.shell.vfs.statSync(full); } catch (_e) { void _e; }
3793
+ if (st && typeof st.isDirectory === 'function' && st.isDirectory()) {
3794
+ collectRawDir(full, isGitTree);
3795
+ } else {
3796
+ try {
3797
+ const rawBuf = this.shell.vfs.readFileSync(full);
3798
+ if (rawBuf instanceof Uint8Array) {
3799
+ if (isGitTree) {
3800
+ gitFilesSnapshot[full.slice('/workspace/.git/'.length)] = new Uint8Array(rawBuf);
3801
+ } else {
3802
+ const rel = full.slice('/workspace/'.length);
3803
+ if (!Object.prototype.hasOwnProperty.call(filesSnapshot, rel)) {
3804
+ binaryFilesSnapshot[rel] = new Uint8Array(rawBuf);
3805
+ }
3806
+ }
3807
+ }
3808
+ } catch (_e) { void _e; }
3809
+ }
3810
+ }
3811
+ };
3812
+ collectRawDir('/workspace', false);
3813
+ }
3666
3814
  this._idbSaveChain = Promise.resolve(this._idbSaveChain).then(() => {
3667
3815
  if (this._idbStorage && typeof this._idbStorage.saveProject === 'function') {
3668
3816
  return this._idbStorage.saveProject({
3669
3817
  id: targetLabId,
3670
3818
  name: targetTitle,
3671
3819
  files: filesSnapshot,
3820
+ binaryFiles: Object.keys(binaryFilesSnapshot).length > 0 ? binaryFilesSnapshot : undefined,
3821
+ gitFiles: Object.keys(gitFilesSnapshot).length > 0 ? gitFilesSnapshot : undefined,
3822
+ gitMeta: stateSnapshot && stateSnapshot.gitState ? stateSnapshot.gitState : undefined,
3672
3823
  updatedAt: savedAt
3673
3824
  });
3674
3825
  }
@@ -3856,7 +4007,7 @@ int main() {
3856
4007
  }
3857
4008
  }
3858
4009
  if (curEl) {
3859
- const showCursor = Boolean(this.activeFile && this.openTabs && this.openTabs.length > 0 && this.activeTab !== '__settings__');
4010
+ const showCursor = Boolean(this.activeFile && this.openTabs && this.openTabs.length > 0 && this.activeTab !== '__settings__' && this.activeTab !== '__welcome__');
3860
4011
  curEl.style.display = showCursor ? 'inline-flex' : 'none';
3861
4012
  if (showCursor && this.cursorPos) {
3862
4013
  curEl.textContent = `Ln ${this.cursorPos.lineNumber || 1}, Col ${this.cursorPos.column || 1}`;
@@ -3871,16 +4022,20 @@ int main() {
3871
4022
  if (langEl) {
3872
4023
  if (this.activeTab === '__settings__') {
3873
4024
  langEl.textContent = 'Settings (UI)';
4025
+ } else if (this.activeTab === '__welcome__') {
4026
+ langEl.textContent = 'Welcome';
4027
+ } else if (this.lang === 'sql' || (this.activeFile && /\.sql$/i.test(this.activeFile))) {
4028
+ langEl.textContent = this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18';
4029
+ } else if (!this.hasGuidedLab && this.activeFile && _wbComponents && typeof _wbComponents.getLanguageDisplayLabel === 'function') {
4030
+ langEl.textContent = _wbComponents.getLanguageDisplayLabel(this.activeFile, this.lang);
3874
4031
  } else {
3875
- langEl.textContent = this.lang === 'sql'
3876
- ? (this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18')
3877
- : this.lang === 'cpp'
3878
- ? 'C++20 (Clang/WASI)'
3879
- : this.lang === 'py'
3880
- ? 'Python 3.12 (CPython WASI)'
3881
- : this.lang === 'ts'
3882
- ? 'TypeScript 5.x'
3883
- : 'JavaScript (CJS/ESM)';
4032
+ langEl.textContent = this.lang === 'cpp'
4033
+ ? 'C++20 (Clang/WASI)'
4034
+ : this.lang === 'py'
4035
+ ? 'Python 3.12 (CPython WASI)'
4036
+ : this.lang === 'ts'
4037
+ ? 'TypeScript 5.x'
4038
+ : 'JavaScript (CJS/ESM)';
3884
4039
  }
3885
4040
  }
3886
4041
  if (typeof this._updateScmActivityBadge === 'function') {
@@ -4154,9 +4309,14 @@ int main() {
4154
4309
  }
4155
4310
 
4156
4311
  _renderLanguageSwitcherHtml() {
4312
+ const isGuided = Boolean(this.hasGuidedLab || (Array.isArray(this.steps) && this.steps.length > 0));
4313
+ if (!isGuided && !(this.options && this.options.showLanguageSelector)) {
4314
+ return '';
4315
+ }
4157
4316
  const hasMulti = Boolean(
4158
4317
  this.hasMultipleLanguages ||
4159
- (this.enabledLanguages && this.enabledLanguages.size > 1)
4318
+ (this.enabledLanguages && this.enabledLanguages.size > 1) ||
4319
+ (this.options && this.options.showLanguageSelector)
4160
4320
  );
4161
4321
  if (!hasMulti) return '';
4162
4322
  const showJs = Boolean(!this.enabledLanguages || this.enabledLanguages.has('js'));
@@ -4400,10 +4560,20 @@ int main() {
4400
4560
  return `<button type="button" class="codelab-activitybar__btn codelab-activitybar__item ${isAct ? 'active' : ''}" data-cl-activity="${escapeHtml(viewId)}" title="${escapeHtml(panel.title || panel.id)}" aria-label="${escapeHtml(panel.title || panel.id)}" aria-pressed="${isAct}">${CL_ICONS.box}</button>`;
4401
4561
  }).join('')
4402
4562
  : '';
4563
+ if (this._hostHasExplicitHeight === undefined) {
4564
+ this._hostHasExplicitHeight = Boolean(
4565
+ this.container &&
4566
+ this.container.children &&
4567
+ this.container.children.length === 0 &&
4568
+ typeof this.container.getBoundingClientRect === 'function' &&
4569
+ this.container.getBoundingClientRect().height > 20
4570
+ );
4571
+ }
4403
4572
  const shellClasses = [
4404
4573
  'codelab',
4405
4574
  'codelab-workbench',
4406
4575
  this.options && this.options.fullbleed ? 'codelab--fullbleed' : '',
4576
+ this._hostHasExplicitHeight ? 'codelab--sized-host' : '',
4407
4577
  isGuideCollapsed ? 'guide-collapsed' : '',
4408
4578
  isSingleSql ? 'is-sql-single-file' : '',
4409
4579
  !this.sidebarVisible ? 'sidebar-collapsed files-collapsed' : '',
@@ -4447,9 +4617,9 @@ int main() {
4447
4617
  <span>${escapeHtml(this.backLabel)}</span>
4448
4618
  </button>
4449
4619
  ` : ''}
4450
- <span class="codelab-brand ${this.onClose ? 'codelab-brand--with-back' : ''}" title="${escapeHtml(brandLabel)}">
4620
+ <span class="codelab-brand ${this.onClose ? 'codelab-brand--with-back' : ''} ${(!this.hasGuidedLab && !this.onClose) ? 'codelab-brand--compact' : ''}" title="${escapeHtml(brandLabel)}">
4451
4621
  <span class="codelab-brand__dot"></span>
4452
- <span>${escapeHtml(brandLabel)}</span>
4622
+ <span class="codelab-brand__label">${escapeHtml(brandLabel)}</span>
4453
4623
  </span>
4454
4624
  <div class="codelab-menubar" id="cl-menubar" role="menubar" aria-label="Application Menu">
4455
4625
  ${menubarHtml}
@@ -4626,9 +4796,19 @@ int main() {
4626
4796
  <button type="button" class="codelab-explorer__btn" data-cl-action="new-folder-root" title="New Folder" aria-label="New Folder">${CL_ICONS.folder}</button>
4627
4797
  <button type="button" class="codelab-explorer__btn" data-cl-action="collapse-all-folders" title="Collapse Folders in Explorer" aria-label="Collapse Folders">${CL_ICONS.collapseAll}</button>
4628
4798
  </div>
4629
- <span id="cl-explorer-lang">${this.lang.toUpperCase()}</span>
4799
+ <span id="cl-explorer-lang" style="display:none">${this.lang.toUpperCase()}</span>
4630
4800
  </div>
4631
4801
  <div class="codelab-explorer__list" id="cl-explorer-list"></div>
4802
+ <div class="codelab-explorer__sections" id="cl-explorer-sections">
4803
+ <details class="codelab-explorer-section" id="cl-explorer-outline">
4804
+ <summary class="codelab-explorer-section__summary"><span>Outline</span></summary>
4805
+ <div class="codelab-explorer-section__body" id="cl-explorer-outline-body"></div>
4806
+ </details>
4807
+ <details class="codelab-explorer-section" id="cl-explorer-timeline">
4808
+ <summary class="codelab-explorer-section__summary"><span>Timeline</span></summary>
4809
+ <div class="codelab-explorer-section__body" id="cl-explorer-timeline-body"></div>
4810
+ </details>
4811
+ </div>
4632
4812
  </div>
4633
4813
 
4634
4814
  <div class="codelab-sidebar__view" id="cl-sidebar-search" data-sidebar-view="search" ${this.activeSidebarView === 'search' ? '' : 'hidden'}>
@@ -4690,6 +4870,7 @@ int main() {
4690
4870
  </div>
4691
4871
  <div class="codelab-md-preview prose" id="cl-md-preview" style="display:none"></div>
4692
4872
  <div class="codelab-settings-host" id="cl-settings-host" role="region" aria-label="Settings Editor" hidden style="display:none"></div>
4873
+ <div class="codelab-welcome-host" id="cl-welcome-host" role="region" aria-label="Welcome" hidden style="display:none"></div>
4693
4874
  <div class="codelab-inline-diff-host" id="cl-inline-diff-container" data-role="scm-diff-host" role="region" aria-label="Source Control Diff View" hidden style="display:none"></div>
4694
4875
  <div class="codelab-empty-editor" id="cl-empty-editor" style="display:none"></div>
4695
4876
  </div>
@@ -4701,10 +4882,10 @@ int main() {
4701
4882
  </div>
4702
4883
 
4703
4884
  <!-- Interactive Horizontal Splitter -->
4704
- <div class="codelab-splitter-h" id="cl-splitter-h" role="separator" aria-orientation="horizontal" title="Drag to resize bottom panel (double-click to reset)"></div>
4885
+ <div class="codelab-splitter-h" id="cl-splitter-h" role="separator" aria-orientation="horizontal" title="Drag to resize or snap-collapse bottom panel (double-click to reset)"></div>
4705
4886
 
4706
4887
  <!-- Region 5: Bottom Panel (Problems / Output / Terminal / Ports / ...) -->
4707
- <section class="codelab-drawer codelab-bottom" id="cl-drawer" aria-label="Bottom Panel">
4888
+ <section class="codelab-drawer codelab-bottom ${this.panelVisible === false ? 'is-minimized' : ''}" id="cl-drawer" aria-label="Bottom Panel">
4708
4889
  <div class="codelab-drawer__bar">
4709
4890
  <div class="codelab-drawer__tabs" role="tablist" aria-label="Execution Output Panels">
4710
4891
  <button type="button" role="tab" tabindex="${this.drawerTab === 'sql-results' ? '0' : '-1'}" aria-selected="${this.drawerTab === 'sql-results'}" class="codelab-drawer__tab ${this.drawerTab === 'sql-results' ? 'active' : ''}" data-cl-drawertab="sql-results" title="SQL Query Results &amp; EXPLAIN Plan" style="display:${showSqlTab ? 'inline-flex' : 'none'}">
@@ -4714,7 +4895,7 @@ int main() {
4714
4895
  <button type="button" role="tab" tabindex="${this.drawerTab === 'problems' ? '0' : '-1'}" aria-selected="${this.drawerTab === 'problems'}" class="codelab-drawer__tab ${this.drawerTab === 'problems' ? 'active' : ''}" data-cl-drawertab="problems" title="Compiler &amp; Runtime Problems">
4715
4896
  ${CL_ICONS.warning}
4716
4897
  <span>Problems</span>
4717
- <span class="codelab-badge" id="cl-problems-count">${this._diagnosticsStore ? this._diagnosticsStore.getAll().length : 0}</span>
4898
+ <span class="codelab-badge" id="cl-problems-count" style="display:${(this._diagnosticsStore && this._diagnosticsStore.getAll().length > 0) ? 'inline-flex' : 'none'}">${this._diagnosticsStore ? this._diagnosticsStore.getAll().length : 0}</span>
4718
4899
  </button>
4719
4900
  <button type="button" role="tab" tabindex="${this.drawerTab === 'output' ? '0' : '-1'}" aria-selected="${this.drawerTab === 'output'}" class="codelab-drawer__tab ${this.drawerTab === 'output' ? 'active' : ''}" data-cl-drawertab="output" title="Workbench &amp; Runtime Output" style="${isSingleSql ? 'display:none' : ''}">
4720
4901
  ${CL_ICONS.code}
@@ -4727,12 +4908,12 @@ int main() {
4727
4908
  <button type="button" role="tab" tabindex="${this.drawerTab === 'ports' ? '0' : '-1'}" aria-selected="${this.drawerTab === 'ports'}" class="codelab-drawer__tab ${this.drawerTab === 'ports' ? 'active' : ''}" data-cl-drawertab="ports" style="${isSingleSql ? 'display:none' : ''}">
4728
4909
  ${CL_ICONS.radio}
4729
4910
  <span>Ports</span>
4730
- <span class="codelab-drawer__pill" id="cl-ports-pill">${this.portTable && typeof this.portTable.listServers === 'function' ? this.portTable.listServers().length : 0} open</span>
4911
+ <span class="codelab-drawer__pill" id="cl-ports-pill" style="display:${(this.portTable && typeof this.portTable.listServers === 'function' && this.portTable.listServers().length > 0) ? 'inline-flex' : 'none'}">${this.portTable && typeof this.portTable.listServers === 'function' ? this.portTable.listServers().length : 0} open</span>
4731
4912
  </button>
4732
4913
  <button type="button" role="tab" tabindex="${this.drawerTab === 'tests' ? '0' : '-1'}" aria-selected="${this.drawerTab === 'tests'}" class="codelab-drawer__tab ${this.drawerTab === 'tests' ? 'active' : ''}" data-cl-drawertab="tests" style="${(isSingleSql && !this._findEntryFile('test')) ? 'display:none' : ''}">
4733
4914
  ${CL_ICONS.check}
4734
4915
  <span>Test Suite</span>
4735
- <span class="codelab-drawer__pill" id="cl-test-pill">Ready</span>
4916
+ <span class="codelab-drawer__pill" id="cl-test-pill" style="display:none">Ready</span>
4736
4917
  </button>
4737
4918
  <button type="button" role="tab" tabindex="${this.drawerTab === 'stdin' ? '0' : '-1'}" aria-selected="${this.drawerTab === 'stdin'}" class="codelab-drawer__tab ${this.drawerTab === 'stdin' ? 'active' : ''}" data-cl-drawertab="stdin" title="Standard Input" style="${isSingleSql ? 'display:none' : ''}">
4738
4919
  ${CL_ICONS.keyboard}
@@ -4745,12 +4926,12 @@ int main() {
4745
4926
  <button type="button" role="tab" tabindex="${this.drawerTab === 'network' ? '0' : '-1'}" aria-selected="${this.drawerTab === 'network'}" class="codelab-drawer__tab ${this.drawerTab === 'network' ? 'active' : ''}" data-cl-drawertab="network" style="${isSingleSql ? 'display:none' : ''}">
4746
4927
  ${CL_ICONS.activity}
4747
4928
  <span>Network</span>
4748
- <span class="codelab-drawer__pill" id="cl-network-pill">${(this.lastHttpTrace || []).length} reqs</span>
4929
+ <span class="codelab-drawer__pill" id="cl-network-pill" style="display:${(this.lastHttpTrace || []).length > 0 ? 'inline-flex' : 'none'}">${(this.lastHttpTrace || []).length} reqs</span>
4749
4930
  </button>
4750
4931
  <button type="button" role="tab" tabindex="${this.drawerTab === 'inspector' ? '0' : '-1'}" aria-selected="${this.drawerTab === 'inspector'}" class="codelab-drawer__tab ${this.drawerTab === 'inspector' ? 'active' : ''}" data-cl-drawertab="inspector" style="${isSingleSql ? 'display:none' : ''}">
4751
4932
  ${CL_ICONS.database}
4752
4933
  <span>Virtual Disk &amp; HTTP</span>
4753
- <span class="codelab-drawer__pill" id="cl-vfs-pill">0 files</span>
4934
+ <span class="codelab-drawer__pill" id="cl-vfs-pill" style="display:none">0 files</span>
4754
4935
  </button>
4755
4936
  ${this.kernel ? `
4756
4937
  <button type="button" role="tab" tabindex="${this.drawerTab === 'observability' ? '0' : '-1'}" aria-selected="${this.drawerTab === 'observability'}" class="codelab-drawer__tab ${this.drawerTab === 'observability' ? 'active' : ''}" data-cl-drawertab="observability" title="Services, Settings &amp; Event Telemetry">
@@ -4764,13 +4945,14 @@ int main() {
4764
4945
  <div class="codelab-drawer__actions">
4765
4946
  <div class="codelab-drawer__term-actions" id="cl-drawer-term-actions" style="display:${isTermDrawer ? 'inline-flex' : 'none'}">
4766
4947
  <div class="codelab-terminal-sessions" id="cl-terminal-sessions"></div>
4767
- <button type="button" class="codelab-btn codelab-btn--icon" id="cl-new-terminal-btn" data-cl-action="new-terminal-session" title="New Terminal (⌃⇧\`)" aria-label="New Terminal Session" style="padding:2px 6px;font-size:11px;">+</button>
4768
- <button type="button" class="codelab-btn codelab-btn--icon" id="cl-kill-terminal-btn" data-cl-action="kill-terminal-session" title="Kill Terminal" aria-label="Kill Active Terminal" style="padding:2px 6px;font-size:11px;">${CL_ICONS.trash}</button>
4769
- <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>
4770
- <button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="clear-terminal" title="Clear Terminal" aria-label="Clear Terminal" style="padding:2px 6px;font-size:11px;">Clear</button>
4948
+ <button type="button" class="codelab-btn codelab-btn--icon" id="cl-new-terminal-btn" data-cl-action="new-terminal-session" title="New Terminal (⌃⇧\`)" aria-label="New Terminal Session">${CL_ICONS.plus}</button>
4949
+ <button type="button" class="codelab-btn codelab-btn--icon" id="cl-split-terminal-btn" data-cl-action="split-terminal-session" title="Split Terminal (⌘\\)" aria-label="Split Terminal">${CL_ICONS.splitHorizontal}</button>
4950
+ <button type="button" class="codelab-btn codelab-btn--icon" id="cl-kill-terminal-btn" data-cl-action="kill-terminal-session" title="Kill Terminal" aria-label="Kill Active Terminal">${CL_ICONS.trash}</button>
4951
+ <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">^C</button>
4952
+ <button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="clear-terminal" title="Clear Terminal (⌘K)" aria-label="Clear Terminal">Clear</button>
4771
4953
  </div>
4772
- <button type="button" class="codelab-btn codelab-btn--icon" id="cl-maximize-drawer-btn" data-cl-action="maximize-drawer" title="Maximize / Restore Panel Size" aria-label="Maximize or Restore Panel Size" aria-pressed="${this.panelMaximized ? 'true' : 'false'}" style="padding:2px 6px;font-size:11px;">${this.panelMaximized ? CL_ICONS.chevronDown : CL_ICONS.chevronUp}</button>
4773
- <button type="button" class="codelab-btn codelab-btn--icon" id="cl-close-drawer-btn" data-cl-action="close-drawer" title="Close Panel (⌘J)" aria-label="Close Panel" style="padding:2px 6px;font-size:11px;">${CL_ICONS.close}</button>
4954
+ <button type="button" class="codelab-btn codelab-btn--icon" id="cl-maximize-drawer-btn" data-cl-action="maximize-drawer" title="Maximize / Restore Panel Size" aria-label="Maximize or Restore Panel Size" aria-pressed="${this.panelMaximized ? 'true' : 'false'}">${this.panelMaximized ? CL_ICONS.chevronDown : CL_ICONS.chevronUp}</button>
4955
+ <button type="button" class="codelab-btn codelab-btn--icon" id="cl-close-drawer-btn" data-cl-action="close-drawer" title="Close Panel (⌘J)" aria-label="Close Panel">${CL_ICONS.close}</button>
4774
4956
  </div>
4775
4957
  </div>
4776
4958
  <div class="codelab-drawer__body" id="cl-drawer-body"></div>
@@ -4778,7 +4960,7 @@ int main() {
4778
4960
  </div>
4779
4961
  </div>
4780
4962
 
4781
- <!-- Interactive 24px Status Bar Footer -->
4963
+ <!-- Interactive 22px Status Bar Footer -->
4782
4964
  <footer class="codelab-statusbar" id="cl-statusbar" role="status" aria-live="polite">
4783
4965
  <div class="codelab-statusbar__left">
4784
4966
  <span class="codelab-statusbar__item" id="cl-status-runtime">
@@ -4802,7 +4984,8 @@ int main() {
4802
4984
  <button type="button" class="codelab-statusbar__btn" id="cl-status-cursor" data-cl-action="go-to-line" title="Go to Line/Column">Ln 1, Col 1</button>
4803
4985
  <button type="button" class="codelab-statusbar__btn" id="cl-status-indent" data-cl-action="open-settings" title="Select Indentation">Spaces: ${tabSizeVal}</button>
4804
4986
  <span class="codelab-statusbar__item">UTF-8</span>
4805
- <button type="button" class="codelab-statusbar__btn" id="cl-status-lang" data-cl-action="open-settings" title="Language Mode">${this.lang === 'sql' ? (this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18') : this.lang === 'cpp' ? 'C++20 (Clang/WASI)' : this.lang === 'py' ? 'Python 3.12 (CPython WASI)' : this.lang === 'ts' ? 'TypeScript 5.x' : 'JavaScript (CJS/ESM)'}</button>
4987
+ <button type="button" class="codelab-statusbar__btn" id="cl-status-lang" data-cl-action="open-settings" title="Select Language Mode">${this.lang === 'sql' ? (this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18') : this.lang === 'cpp' ? 'C++20 (Clang/WASI)' : this.lang === 'py' ? 'Python 3.12 (CPython WASI)' : this.lang === 'ts' ? 'TypeScript 5.x' : 'JavaScript (CJS/ESM)'}</button>
4988
+ <button type="button" class="codelab-statusbar__btn" id="cl-status-panel-toggle" data-cl-action="toggle-drawer" title="Toggle Panel (⌘J)" aria-label="Toggle Panel">${CL_ICONS.panelBottom}</button>
4806
4989
  </div>
4807
4990
  </footer>
4808
4991
 
@@ -4815,7 +4998,10 @@ int main() {
4815
4998
  </div>
4816
4999
  `;
4817
5000
 
4818
- if (this.themeOption !== 'auto' && this.themes && typeof this.themes.applyToElement === 'function') {
5001
+ if (this.themeOption === 'auto') {
5002
+ this._ensureSystemColorSchemeListener();
5003
+ }
5004
+ if (this.themes && typeof this.themes.applyToElement === 'function') {
4819
5005
  const shellEl = this.container.querySelector('.codelab');
4820
5006
  if (shellEl && shellEl.style && typeof shellEl.style.setProperty === 'function') {
4821
5007
  try {
@@ -4906,6 +5092,13 @@ int main() {
4906
5092
  }
4907
5093
  }
4908
5094
  const code = this.files[filePath];
5095
+ if (_wbComponents && typeof _wbComponents.findEnclosingSymbolAtLine === 'function') {
5096
+ const curLine = (this.cursorPos && this.cursorPos.lineNumber) ? this.cursorPos.lineNumber : 1;
5097
+ const sym = _wbComponents.findEnclosingSymbolAtLine(filePath, code, curLine);
5098
+ if (sym && sym.name) {
5099
+ return sym.containerName ? `${sym.containerName}.${sym.name}` : sym.name;
5100
+ }
5101
+ }
4909
5102
  const classMatch = code.match(/\bclass\s+([A-Za-z_$][A-Za-z0-9_$]*)/);
4910
5103
  if (classMatch) return classMatch[1];
4911
5104
  const fnMatch = code.match(/\b(?:async\s+)?function\s+([A-Za-z_$][A-Za-z0-9_$]*)/);
@@ -4916,7 +5109,7 @@ int main() {
4916
5109
  _renderBreadcrumbs() {
4917
5110
  const host = this.container.querySelector('#cl-breadcrumbs');
4918
5111
  if (!host) return;
4919
- if (!this.activeFile || !this.openTabs || this.openTabs.length === 0 || this.activeTab === '__settings__') {
5112
+ if (!this.activeFile || !this.openTabs || this.openTabs.length === 0 || this.activeTab === '__settings__' || this.activeTab === '__welcome__') {
4920
5113
  host.innerHTML = '';
4921
5114
  host.hidden = true;
4922
5115
  if (host.style) host.style.display = 'none';
@@ -5101,7 +5294,7 @@ int main() {
5101
5294
  </div>
5102
5295
  ` : `
5103
5296
  <div class="codelab-guide__footer-row">
5104
- <span style="font-size:11.5px;color:var(--cl-fg-muted);">100% In-Browser Web Worker Sandbox</span>
5297
+ <span class="cl-ui-muted-note">100% In-Browser Web Worker Sandbox</span>
5105
5298
  </div>
5106
5299
  `}
5107
5300
  `;
@@ -5441,13 +5634,31 @@ int main() {
5441
5634
  }
5442
5635
  }
5443
5636
 
5637
+ const gitStatusMap = new Map();
5638
+ if (typeof this.getGitStatus === 'function') {
5639
+ try {
5640
+ for (const entry of (this.getGitStatus() || [])) {
5641
+ if (entry && entry.path) {
5642
+ const rawSt = String(entry.status || '').toLowerCase();
5643
+ const code = rawSt.includes('untracked') ? 'U'
5644
+ : rawSt.includes('added') ? 'A'
5645
+ : rawSt.includes('deleted') ? 'D'
5646
+ : 'M';
5647
+ gitStatusMap.set(entry.path, code);
5648
+ }
5649
+ }
5650
+ } catch (_e) { void _e; }
5651
+ }
5444
5652
  const sortedFiles = Array.from(node.files.entries()).sort((a, b) => a[0].localeCompare(b[0]));
5445
5653
  for (const [baseName, fullPath] of sortedFiles) {
5446
5654
  const isActive = fullPath === this.activeFile;
5447
5655
  const badge = fullPath.endsWith('.md') ? 'DOC' : fullPath.endsWith('.json') ? 'PKG' : /\.sql$/i.test(fullPath) ? 'SQL' : /(^|\/)test\./i.test(fullPath) ? 'TEST' : /(^|\/)(demo|main)\./i.test(fullPath) ? 'DEMO' : /\.(hpp|h)$/i.test(fullPath) ? 'HDR' : 'SRC';
5448
5656
  const ext = /\.(cpp|cc|cxx|hpp|h)$/i.test(fullPath) ? 'cpp' : /\.sql$/i.test(fullPath) ? 'sql' : fullPath.endsWith('.py') ? 'py' : fullPath.endsWith('.ts') ? 'ts' : fullPath.endsWith('.js') ? 'js' : fullPath.endsWith('.json') ? 'json' : fullPath.endsWith('.md') ? 'md' : 'txt';
5449
- const fileIcon = (ext === 'json' || ext === 'sql') ? CL_ICONS.database : ext === 'md' ? CL_ICONS.book : CL_ICONS.file;
5657
+ const fileIcon = (_wbComponents && typeof _wbComponents.getFileIconSvg === 'function')
5658
+ ? _wbComponents.getFileIconSvg(baseName)
5659
+ : ((ext === 'json' || ext === 'sql') ? CL_ICONS.database : ext === 'md' ? CL_ICONS.book : CL_ICONS.file);
5450
5660
  const indent = depth * 14 + 10;
5661
+ const gitBadgeCode = gitStatusMap.get(fullPath) || '';
5451
5662
  const isRenamingFile = Boolean(
5452
5663
  this.renamingItem &&
5453
5664
  this.renamingItem.type === 'file' &&
@@ -5466,11 +5677,11 @@ int main() {
5466
5677
  } else {
5467
5678
  const isFileDirty = Boolean(this._dirtyFiles && this._dirtyFiles.has(fullPath));
5468
5679
  treeHtml += `
5469
- <button type="button" class="codelab-file-item ${isActive ? 'active' : ''}"${isFileDirty ? ' data-dirty="true"' : ''} draggable="true" data-cl-file="${escapeHtml(fullPath)}" data-file="${escapeHtml(fullPath)}" data-depth="${depth}" style="padding-left: ${indent}px;">
5680
+ <button type="button" class="codelab-file-item ${isActive ? 'active' : ''}"${isFileDirty ? ' data-dirty="true"' : ''}${gitBadgeCode ? ` data-git-status="${gitBadgeCode}"` : ''} draggable="true" data-cl-file="${escapeHtml(fullPath)}" data-file="${escapeHtml(fullPath)}" data-depth="${depth}" style="padding-left: ${indent}px;">
5470
5681
  <span class="codelab-file-icon">${fileIcon}</span>
5471
5682
  <span class="codelab-file-name" title="${escapeHtml(baseName)}">${escapeHtml(baseName)}</span>
5472
5683
  ${isFileDirty ? '<span class="codelab-file-dirty" title="Unsaved changes" aria-hidden="true"></span>' : ''}
5473
- <span class="codelab-file-badge">${badge}</span>
5684
+ ${gitBadgeCode ? `<span class="codelab-file-git-status codelab-file-git-status--${gitBadgeCode.toLowerCase()}" aria-label="Git ${gitBadgeCode}">${gitBadgeCode}</span>` : `<span class="codelab-file-badge">${badge}</span>`}
5474
5685
  </button>
5475
5686
  `;
5476
5687
  }
@@ -5815,22 +6026,37 @@ int main() {
5815
6026
 
5816
6027
  // Tabs rendering (strictly WAI-ARIA compliant: zero nested <button> inside [role="tab"]!)
5817
6028
  const openTabs = Array.isArray(this.openTabs) ? this.openTabs : [];
5818
- const effectiveActiveTab = this.settingsTabOpen && this.activeTab === '__settings__'
6029
+ const effectiveActiveTab = (this.settingsTabOpen && this.activeTab === '__settings__')
5819
6030
  ? '__settings__'
5820
- : this.activeFile;
6031
+ : (this.welcomeTabOpen && this.activeTab === '__welcome__')
6032
+ ? '__welcome__'
6033
+ : this.activeFile;
6034
+ const hasCustomFileIcons = Boolean(_wbComponents && typeof _wbComponents.getFileIconSvg === 'function');
5821
6035
  const tabsHtml = openTabs.map(f => {
5822
6036
  const isActive = f === effectiveActiveTab;
5823
6037
  const isDirty = Boolean(this._dirtyFiles && this._dirtyFiles.has(f));
5824
6038
  const ext = /\.(cpp|cc|cxx|hpp|h)$/i.test(f) ? 'cpp' : /\.sql$/i.test(f) ? 'sql' : f.endsWith('.py') ? 'py' : f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
6039
+ const tabIconHtml = hasCustomFileIcons
6040
+ ? _wbComponents.getFileIconSvg(f)
6041
+ : (ext === 'cpp' ? 'C++' : ext.toUpperCase());
5825
6042
  return `
5826
6043
  <div role="tab" tabindex="${isActive ? '0' : '-1'}" aria-selected="${isActive}"${isDirty ? ' data-dirty="true"' : ''} class="codelab-tab ${isActive ? 'active' : ''}" data-cl-file="${escapeHtml(f)}" data-tab-file="${escapeHtml(f)}">
5827
- <span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext === 'cpp' ? 'C++' : ext.toUpperCase()}</span>
6044
+ <span class="codelab-tab__ext codelab-tab__ext--${ext}">${tabIconHtml}</span>
5828
6045
  <span class="codelab-tab__label">${escapeHtml(f)}</span>
5829
6046
  ${isDirty ? '<span class="codelab-tab__dirty" title="Unsaved changes" aria-hidden="true"></span>' : ''}
5830
6047
  <span role="button" tabindex="0" class="codelab-tab__close" data-action="close-tab" data-cl-close-file="${escapeHtml(f)}" title="Close ${escapeHtml(f)}" aria-label="Close ${escapeHtml(f)}">×</span>
5831
6048
  </div>
5832
6049
  `;
5833
6050
  }).join('');
6051
+ const welcomeTabHtml = this.welcomeTabOpen
6052
+ ? `
6053
+ <div role="tab" tabindex="${effectiveActiveTab === '__welcome__' ? '0' : '-1'}" aria-selected="${effectiveActiveTab === '__welcome__'}" class="codelab-tab ${effectiveActiveTab === '__welcome__' ? 'active' : ''}" data-cl-tab="__welcome__" data-tab-file="__welcome__">
6054
+ <span class="codelab-tab__ext codelab-tab__ext--md">${CL_ICONS.code}</span>
6055
+ <span class="codelab-tab__label">Welcome</span>
6056
+ <span role="button" tabindex="0" class="codelab-tab__close" data-action="close-tab" data-cl-close-tab="__welcome__" title="Close Welcome" aria-label="Close Welcome">×</span>
6057
+ </div>
6058
+ `
6059
+ : '';
5834
6060
  const settingsTabHtml = this.settingsTabOpen
5835
6061
  ? `
5836
6062
  <div role="tab" tabindex="${effectiveActiveTab === '__settings__' ? '0' : '-1'}" aria-selected="${effectiveActiveTab === '__settings__'}" class="codelab-tab ${effectiveActiveTab === '__settings__' ? 'active' : ''}" data-cl-tab="__settings__" data-tab-file="__settings__">
@@ -5853,17 +6079,18 @@ int main() {
5853
6079
  <button type="button" class="codelab-pkg-btn" data-cl-action="open-packages" title="Manage Dependencies &amp; Built-ins">
5854
6080
  ${CL_ICONS.package}
5855
6081
  <span>Packages</span>
5856
- <span class="codelab-drawer__pill" style="padding:0 5px;font-size:10px;">${pkgBadge}</span>
6082
+ <span class="codelab-drawer__pill">${pkgBadge}</span>
5857
6083
  </button>
5858
6084
  `;
5859
6085
 
5860
- const mdToggleHtml = (this.activeFile && /\.md$/i.test(this.activeFile) && effectiveActiveTab !== '__settings__')
6086
+ const mdToggleHtml = (this.activeFile && /\.md$/i.test(this.activeFile) && effectiveActiveTab !== '__settings__' && effectiveActiveTab !== '__welcome__')
5861
6087
  ? `<button type="button" class="codelab-pkg-btn ${this._mdPreviewOpen ? 'active' : ''}" data-cl-action="toggle-md-preview" aria-pressed="${Boolean(this._mdPreviewOpen)}" title="${this._mdPreviewOpen ? 'Edit Markdown Source' : 'Open Markdown Preview'}">
5862
6088
  <span>${this._mdPreviewOpen ? 'Edit Source' : 'Preview'}</span>
5863
6089
  </button>`
5864
6090
  : '';
5865
6091
 
5866
- tabsEl.innerHTML = tabsHtml + settingsTabHtml;
6092
+ tabsEl.innerHTML = welcomeTabHtml + tabsHtml + settingsTabHtml;
6093
+ this._renderExplorerOutlineAndTimeline();
5867
6094
  const tabsActionsEl = this.container.querySelector('#cl-file-tabs-actions');
5868
6095
  if (tabsActionsEl) {
5869
6096
  tabsActionsEl.innerHTML = mdToggleHtml + newFileControl + pkgBtnHtml;
@@ -6539,6 +6766,10 @@ int main() {
6539
6766
  this.closeSettings();
6540
6767
  return;
6541
6768
  }
6769
+ if (filename === '__welcome__') {
6770
+ this.closeWelcomeTab();
6771
+ return;
6772
+ }
6542
6773
  if (!Array.isArray(this.openTabs) || !this.openTabs.includes(filename)) {
6543
6774
  return;
6544
6775
  }
@@ -6553,7 +6784,7 @@ int main() {
6553
6784
  this.activeFile = null;
6554
6785
  }
6555
6786
  }
6556
- if (this.activeTab !== '__settings__') {
6787
+ if (this.activeTab !== '__settings__' && this.activeTab !== '__welcome__') {
6557
6788
  this.activeTab = this.activeFile;
6558
6789
  }
6559
6790
 
@@ -6565,16 +6796,31 @@ int main() {
6565
6796
  if (keepFilename === '__settings__') {
6566
6797
  this.openTabs = [];
6567
6798
  this.activeFile = null;
6799
+ this.welcomeTabOpen = false;
6568
6800
  this.activeTab = '__settings__';
6569
6801
  this._saveState();
6570
6802
  this._syncActiveFileToView();
6571
6803
  return;
6572
6804
  }
6805
+ if (keepFilename === '__welcome__') {
6806
+ this.openTabs = [];
6807
+ this.activeFile = null;
6808
+ this.settingsTabOpen = false;
6809
+ this.welcomeTabOpen = true;
6810
+ this.activeTab = '__welcome__';
6811
+ if (this._settingsDialog && typeof this._settingsDialog.unmountInline === 'function') {
6812
+ this._settingsDialog.unmountInline();
6813
+ }
6814
+ this._saveState();
6815
+ this._syncActiveFileToView();
6816
+ return;
6817
+ }
6573
6818
  if (!Array.isArray(this.openTabs)) return;
6574
6819
  if (keepFilename && this.files[keepFilename] !== undefined) {
6575
6820
  this.openTabs = [keepFilename];
6576
6821
  this.activeFile = keepFilename;
6577
6822
  this.settingsTabOpen = false;
6823
+ this.welcomeTabOpen = false;
6578
6824
  this.activeTab = keepFilename;
6579
6825
  if (this._settingsDialog && typeof this._settingsDialog.unmountInline === 'function') {
6580
6826
  this._settingsDialog.unmountInline();
@@ -6588,6 +6834,7 @@ int main() {
6588
6834
  this.openTabs = [];
6589
6835
  this.activeFile = null;
6590
6836
  this.settingsTabOpen = false;
6837
+ this.welcomeTabOpen = false;
6591
6838
  this.activeTab = null;
6592
6839
  if (this._settingsDialog && typeof this._settingsDialog.unmountInline === 'function') {
6593
6840
  this._settingsDialog.unmountInline();
@@ -6688,6 +6935,9 @@ int main() {
6688
6935
  ? this._diagnosticsStore.getAll().length
6689
6936
  : 0;
6690
6937
  problemsCountEl.textContent = String(count);
6938
+ if (problemsCountEl.style) {
6939
+ problemsCountEl.style.display = count > 0 ? 'inline-flex' : 'none';
6940
+ }
6691
6941
  }
6692
6942
  this._updateTelemetryHud();
6693
6943
 
@@ -6695,11 +6945,13 @@ int main() {
6695
6945
  if (!this.lastTestResults.length) {
6696
6946
  testPill.textContent = 'Ready';
6697
6947
  testPill.className = 'codelab-drawer__pill';
6948
+ if (testPill.style) testPill.style.display = 'none';
6698
6949
  } else {
6699
6950
  const passed = this.lastTestResults.filter(t => t.status === 'pass').length;
6700
6951
  const total = this.lastTestResults.length;
6701
6952
  testPill.textContent = `${passed}/${total} Passed`;
6702
6953
  testPill.className = `codelab-drawer__pill ${passed === total ? 'pass' : 'fail'}`;
6954
+ if (testPill.style) testPill.style.display = 'inline-flex';
6703
6955
  }
6704
6956
  }
6705
6957
  if (portsPill) {
@@ -6707,15 +6959,25 @@ int main() {
6707
6959
  ? this.portTable.listServers().length
6708
6960
  : 0;
6709
6961
  portsPill.textContent = `${portCount} open`;
6962
+ if (portsPill.style) portsPill.style.display = portCount > 0 ? 'inline-flex' : 'none';
6710
6963
  }
6711
6964
  if (networkPill) {
6712
6965
  const netCount = (this.lastHttpTrace || []).length;
6713
6966
  networkPill.textContent = `${netCount} reqs`;
6967
+ if (networkPill.style) networkPill.style.display = netCount > 0 ? 'inline-flex' : 'none';
6714
6968
  }
6715
6969
  if (vfsPill) {
6716
6970
  const diskCount = this.lastFsSnapshot.length;
6717
6971
  const httpCount = this.lastHttpTrace.length;
6718
6972
  vfsPill.textContent = httpCount > 0 ? `${diskCount} files · ${httpCount} reqs` : `${diskCount} files`;
6973
+ if (vfsPill.style) vfsPill.style.display = (diskCount > 0 || httpCount > 0) ? 'inline-flex' : 'none';
6974
+ }
6975
+
6976
+ if (bodyEl && bodyEl.classList) {
6977
+ bodyEl.classList.toggle('is-flush-panel', this.drawerTab === 'terminal');
6978
+ }
6979
+ if (this.drawerTab !== 'terminal' && this._xtermWrapEl && this._xtermWrapEl.parentNode === bodyEl) {
6980
+ try { bodyEl.removeChild(this._xtermWrapEl); } catch (_err) { void _err; }
6719
6981
  }
6720
6982
 
6721
6983
  if (this.drawerTab === 'problems') {
@@ -6725,12 +6987,12 @@ int main() {
6725
6987
 
6726
6988
  if (this.drawerTab === 'stdin') {
6727
6989
  bodyEl.innerHTML = `
6728
- <div class="codelab-stdin-panel" style="padding:10px;height:100%;display:flex;flex-direction:column;box-sizing:border-box;">
6729
- <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:6px;font-size:12px;color:var(--cl-fg-muted);">
6990
+ <div class="codelab-stdin-panel">
6991
+ <div class="codelab-stdin-panel__header">
6730
6992
  <span>Standard Input (std::cin / sys.stdin / process.stdin)</span>
6731
- <button type="button" class="codelab-btn codelab-btn--sm" id="cl-stdin-clear-btn" style="padding:2px 8px;font-size:11px;">Clear</button>
6993
+ <button type="button" class="codelab-btn codelab-btn--sm" id="cl-stdin-clear-btn">Clear</button>
6732
6994
  </div>
6733
- <textarea id="cl-stdin-textarea" class="codelab-stdin-textarea" style="flex:1;width:100%;background:var(--cl-bg-input, #1e1e1e);color:var(--cl-fg, #d4d4d4);border:1px solid var(--cl-border, #333);border-radius:4px;padding:8px;font-family:var(--cl-font-mono, monospace);font-size:12px;resize:none;outline:none;box-sizing:border-box;" placeholder="Enter or paste custom stdin here (used by std::cin, sys.stdin, fs.readFileSync(0))...">${escapeHtml(this.customStdin || '')}</textarea>
6995
+ <textarea id="cl-stdin-textarea" class="codelab-stdin-textarea codelab-stdin-panel__textarea" placeholder="Enter or paste custom stdin here (used by std::cin, sys.stdin, fs.readFileSync(0))...">${escapeHtml(this.customStdin || '')}</textarea>
6734
6996
  </div>
6735
6997
  `;
6736
6998
  const ta = bodyEl.querySelector('#cl-stdin-textarea');
@@ -6766,9 +7028,9 @@ int main() {
6766
7028
  <div class="codelab-test-summary ${passed === total ? 'all-pass' : 'has-fail'}">
6767
7029
  <div>
6768
7030
  <strong>${passed === total ? `All ${total} Tests Passing` : `${passed} of ${total} Tests Passing`}</strong>
6769
- ${this.steps.length ? `<span style="margin-left:8px;font-size:12px;opacity:0.8;">(${this.completedSteps.size}/${this.steps.length} Guided Steps Complete)</span>` : ''}
7031
+ ${this.steps.length ? `<span class="cl-ui-meta-inline">(${this.completedSteps.size}/${this.steps.length} Guided Steps Complete)</span>` : ''}
6770
7032
  </div>
6771
- <span style="font-family:var(--cl-font-mono);font-size:12px;">${totalMs} ms</span>
7033
+ <span class="cl-ui-metric">${totalMs} ms</span>
6772
7034
  </div>
6773
7035
  <div class="codelab-test-list">
6774
7036
  ${this.lastTestResults.map(t => `
@@ -6803,7 +7065,7 @@ int main() {
6803
7065
  const html = ansiToHtml ? ansiToHtml(item.text || '') : escapeHtml(item.text || '');
6804
7066
  return `<div class="codelab-log-line ${escapeHtml(item.type || '')}">${html}</div>`;
6805
7067
  }).join('')
6806
- : `<div style="color:var(--cl-fg-muted);font-size:12px;">No output messages yet. Run your code or workspace tasks to inspect output logs.</div>`;
7068
+ : `<div class="cl-ui-muted-note">No output messages yet. Run your code or workspace tasks to inspect output logs.</div>`;
6807
7069
  bodyEl.innerHTML = `<div class="codelab-output-panel" id="cl-output-surface" style="font-size:${termFontPx}px;line-height:1.5;">${linesHtml}</div>`;
6808
7070
  bodyEl.scrollTop = bodyEl.scrollHeight;
6809
7071
  return;
@@ -6815,6 +7077,10 @@ int main() {
6815
7077
  const termFontPx = this.configuration
6816
7078
  ? Math.max(10, Math.min(28, Number(this.configuration.get('terminal.fontSize', 13)) || 13))
6817
7079
  : 13;
7080
+ if (this._shouldUseXterm()) {
7081
+ this._renderXtermTerminalBody(bodyEl, termFontPx);
7082
+ return;
7083
+ }
6818
7084
  const logsHtml = this.terminalLogs
6819
7085
  .map(item => {
6820
7086
  const html = ansiToHtml ? ansiToHtml(item.text || '') : escapeHtml(item.text || '');
@@ -6990,7 +7256,7 @@ int main() {
6990
7256
  <span style="display:inline-flex;align-items:center;gap:6px;">${CL_ICONS.database}<span>Virtual POSIX File System (${tmpFiles.length} files)</span></span>
6991
7257
  <span>In-Memory VFS</span>
6992
7258
  </div>
6993
- ${tmpFiles.length === 0 ? `<div style="color:var(--cl-fg-muted);font-size:12px;">Run Demo or Tests to inspect virtual files (e.g. /tmp WAL segments &amp; SSTables).</div>` : ''}
7259
+ ${tmpFiles.length === 0 ? `<div class="cl-ui-muted-note">Run Demo or Tests to inspect virtual files (e.g. /tmp WAL segments &amp; SSTables).</div>` : ''}
6994
7260
  ${tmpFiles.map(f => `
6995
7261
  <div class="codelab-vfs-item">
6996
7262
  <div class="codelab-vfs-item__head">
@@ -7008,7 +7274,7 @@ int main() {
7008
7274
  <span style="display:inline-flex;align-items:center;gap:6px;">${CL_ICONS.globe}<span>Virtual Loopback HTTP Trace (${this.lastHttpTrace.length} requests)</span></span>
7009
7275
  <span>127.0.0.1</span>
7010
7276
  </div>
7011
- ${this.lastHttpTrace.length === 0 ? `<div style="color:var(--cl-fg-muted);font-size:12px;">Virtual HTTP loopback requests (e.g., Layer-7 Load Balancer traffic &amp; active health probes) appear here.</div>` : ''}
7277
+ ${this.lastHttpTrace.length === 0 ? `<div class="cl-ui-muted-note">Virtual HTTP loopback requests (e.g., Layer-7 Load Balancer traffic &amp; active health probes) appear here.</div>` : ''}
7012
7278
  ${this.lastHttpTrace.map(req => `
7013
7279
  <div class="codelab-vfs-item">
7014
7280
  <div class="codelab-vfs-item__head">
@@ -7039,13 +7305,13 @@ int main() {
7039
7305
  ? `<div class="codelab-test-summary ${res.verification.passed ? 'all-pass' : 'has-fail'}" style="margin-bottom:10px;">
7040
7306
  <div>
7041
7307
  <strong>${res.verification.passed ? '✓ Step Verification Passed' : '✖ Step Verification Failed'}</strong>
7042
- ${res.verification.message ? `<span style="margin-left:8px;font-size:12px;">${escapeHtml(res.verification.message)}</span>` : ''}
7308
+ ${res.verification.message ? `<span class="cl-ui-meta-inline">${escapeHtml(res.verification.message)}</span>` : ''}
7043
7309
  </div>
7044
- <span style="font-family:var(--cl-font-mono);font-size:12px;">${typeof res.durationMs === 'number' ? `${res.durationMs.toFixed(1)} ms` : ''}</span>
7310
+ <span class="cl-ui-metric">${typeof res.durationMs === 'number' ? `${res.durationMs.toFixed(1)} ms` : ''}</span>
7045
7311
  </div>`
7046
7312
  : '';
7047
7313
  const errHtml = res.error
7048
- ? `<div role="alert" style="padding:10px 12px;margin-bottom:10px;border-radius:6px;border:1px solid rgba(239,68,68,0.45);background:rgba(239,68,68,0.12);color:var(--cl-red,#f87171);font-family:var(--cl-font-mono);font-size:12px;white-space:pre-wrap;">${escapeHtml(typeof res.error === 'string' ? res.error : (res.error.message || String(res.error)))}</div>`
7314
+ ? `<div role="alert" class="cl-ui-alert-error">${escapeHtml(typeof res.error === 'string' ? res.error : (res.error.message || String(res.error)))}</div>`
7049
7315
  : '';
7050
7316
  const cols = Array.isArray(res.columns) ? res.columns : [];
7051
7317
  const rows = Array.isArray(res.rows) ? res.rows : [];
@@ -7079,12 +7345,12 @@ int main() {
7079
7345
  </table>
7080
7346
  </div>`
7081
7347
  : (!res.error
7082
- ? `<div style="color:var(--cl-fg-muted);font-size:12px;padding:8px 2px;">Statement executed (${escapeHtml(rowSummary)}).</div>`
7348
+ ? `<div class="cl-ui-muted-note" style="padding:8px 2px;">Statement executed (${escapeHtml(rowSummary)}).</div>`
7083
7349
  : '');
7084
7350
  const planHtml = res.plan
7085
7351
  ? `<div style="margin-top:10px;">
7086
- <div style="font-size:11px;font-weight:600;color:var(--cl-fg-muted);margin-bottom:4px;text-transform:uppercase;letter-spacing:0.05em;">Query Execution Plan</div>
7087
- <pre style="margin:0;padding:10px;border-radius:6px;border:1px solid var(--cl-border,#262626);background:var(--cl-bg,#0a0a0a);color:var(--cl-fg,#f5f5f5);font-family:var(--cl-font-mono);font-size:11.5px;overflow:auto;">${escapeHtml(typeof res.plan === 'string' ? res.plan : JSON.stringify(res.plan, null, 2))}</pre>
7352
+ <div class="cl-ui-section-label">Query Execution Plan</div>
7353
+ <pre class="cl-ui-code-box">${escapeHtml(typeof res.plan === 'string' ? res.plan : JSON.stringify(res.plan, null, 2))}</pre>
7088
7354
  </div>`
7089
7355
  : '';
7090
7356
  bodyEl.innerHTML = `<div style="padding:10px;">${verificationHtml}${errHtml}${tableHtml}${planHtml}</div>`;
@@ -7103,7 +7369,7 @@ int main() {
7103
7369
  workerStatus: this.runtimeStatusText || 'Idle'
7104
7370
  });
7105
7371
  } else {
7106
- bodyEl.innerHTML = `<div style="padding:14px;color:var(--cl-fg-muted);font-size:12px;">Observability kernel is not initialized.</div>`;
7372
+ bodyEl.innerHTML = `<div class="cl-ui-muted-note" style="padding:14px;">Observability kernel is not initialized.</div>`;
7107
7373
  }
7108
7374
  return;
7109
7375
  }
@@ -7136,7 +7402,14 @@ int main() {
7136
7402
  if (chunk === null || chunk === undefined || chunk === '') return;
7137
7403
  const rawText = String(chunk);
7138
7404
 
7139
- if (this.ptyEngine && this.ptyEngine.container && typeof this.ptyEngine.writeStreamChunk === 'function') {
7405
+ const activeXterm = this._getActiveXtermEngine();
7406
+ if (activeXterm && typeof activeXterm.writeStreamChunk === 'function') {
7407
+ try {
7408
+ activeXterm.writeStreamChunk(rawText, type);
7409
+ } catch (err) {
7410
+ this.logger.debug('activeXterm.writeStreamChunk failed.', err);
7411
+ }
7412
+ } else if (this.ptyEngine && this.ptyEngine.container && typeof this.ptyEngine.writeStreamChunk === 'function') {
7140
7413
  try {
7141
7414
  this.ptyEngine.writeStreamChunk(rawText, type);
7142
7415
  } catch (err) {
@@ -7149,10 +7422,8 @@ int main() {
7149
7422
  const termSurface = this.container ? this.container.querySelector('#cl-terminal-surface') : null;
7150
7423
  const drawerBody = this.container ? this.container.querySelector('.codelab-drawer__body') : null;
7151
7424
 
7152
- // The workbench owns live terminal rendering. Only defer when an attached PTY
7153
- // engine is itself rendering into the DOM (it is created with a null container in
7154
- // production, so this remains the sole renderer there).
7155
- const ptyOwnsDom = Boolean(this.ptyEngine && this.ptyEngine.container);
7425
+ // The workbench owns live terminal rendering unless xterm or an attached PTY engine owns the DOM.
7426
+ const ptyOwnsDom = Boolean((activeXterm && activeXterm.container) || (this.ptyEngine && this.ptyEngine.container));
7156
7427
  const canPatchDom = Boolean(termLogEl && typeof document !== 'undefined' && !ptyOwnsDom);
7157
7428
 
7158
7429
  // Write a single logical line into the live terminal DOM immediately, so output
@@ -7178,7 +7449,7 @@ int main() {
7178
7449
  const maxScrollback = this._getTerminalScrollback();
7179
7450
  const commitActiveLine = () => {
7180
7451
  const entry = { type: this._activeStreamType || type, text: this._activeStreamLine };
7181
- this._pushTerminalLog(entry);
7452
+ this._pushTerminalLog(entry, { fromStream: true });
7182
7453
  if (Array.isArray(this.outputLogs)) {
7183
7454
  this.outputLogs.push(entry);
7184
7455
  if (this.outputLogs.length > maxScrollback) {
@@ -7297,11 +7568,30 @@ int main() {
7297
7568
  return trimmed;
7298
7569
  }
7299
7570
 
7300
- _pushTerminalLog(entry) {
7571
+ _pushTerminalLog(entry, opts = null) {
7301
7572
  if (!entry) return;
7573
+ const activeXterm = this._getActiveXtermEngine();
7574
+ if (activeXterm && activeXterm.logs === this.terminalLogs) {
7575
+ if (!(opts && opts.fromStream) && typeof activeXterm.writeln === 'function') {
7576
+ try {
7577
+ activeXterm.writeln(String(entry.text ?? ''), entry.type || 'stdout');
7578
+ } catch (_err) {
7579
+ void _err;
7580
+ }
7581
+ }
7582
+ this._trimTerminalLogs();
7583
+ return;
7584
+ }
7302
7585
  if (Array.isArray(this.terminalLogs)) {
7303
7586
  Array.prototype.push.call(this.terminalLogs, entry);
7304
7587
  }
7588
+ if (activeXterm && !(opts && opts.fromStream) && typeof activeXterm.writeln === 'function') {
7589
+ try {
7590
+ activeXterm.writeln(String(entry.text ?? ''), entry.type || 'stdout');
7591
+ } catch (_err) {
7592
+ void _err;
7593
+ }
7594
+ }
7305
7595
  this._trimTerminalLogs();
7306
7596
  }
7307
7597
 
@@ -7318,7 +7608,7 @@ int main() {
7318
7608
  type: this._activeStreamType || 'stdout',
7319
7609
  text: this._activeStreamLine
7320
7610
  };
7321
- this._pushTerminalLog(entry);
7611
+ this._pushTerminalLog(entry, { fromStream: true });
7322
7612
  const maxScrollback = this._getTerminalScrollback();
7323
7613
  if (this.terminalLogs.length > maxScrollback) {
7324
7614
  this.terminalLogs.splice(0, this.terminalLogs.length - maxScrollback);
@@ -7361,15 +7651,55 @@ int main() {
7361
7651
  `;
7362
7652
  }
7363
7653
 
7364
- _handleInterrupt() {
7654
+ interruptTerminal() {
7655
+ return Boolean(this._handleInterrupt());
7656
+ }
7657
+
7658
+ submitTerminalStdin(line) {
7659
+ const activeXterm = this._getActiveXtermEngine();
7660
+ if (activeXterm && typeof activeXterm.submitLine === 'function') {
7661
+ activeXterm.buffer = String(line ?? '');
7662
+ activeXterm.cursor = activeXterm.buffer.length;
7663
+ activeXterm.submitLine();
7664
+ return true;
7665
+ }
7666
+ if (this.ptyEngine && typeof this.ptyEngine.submitLine === 'function') {
7667
+ this.ptyEngine.buffer = String(line ?? '');
7668
+ this.ptyEngine.cursor = this.ptyEngine.buffer.length;
7669
+ this.ptyEngine.submitLine();
7670
+ return true;
7671
+ }
7672
+ return false;
7673
+ }
7674
+
7675
+ _submitInteractiveTerminalStdin(line) {
7676
+ return this.submitTerminalStdin(line);
7677
+ }
7678
+
7679
+ _handleInterrupt(opts = null) {
7680
+ const fromXterm = Boolean(opts && opts.fromXterm);
7681
+ let didInterrupt = false;
7365
7682
  if (this._cloneInFlight || this._activeCloneAbortController) {
7366
7683
  this.cancelClone();
7684
+ didInterrupt = true;
7685
+ }
7686
+ let cancelledWorker = false;
7687
+ if (typeof root.CodeLabRuntime?.cancelWorkerExecution === 'function') {
7688
+ try {
7689
+ cancelledWorker = Boolean(
7690
+ root.CodeLabRuntime.cancelWorkerExecution('SIGINT: Interrupted by user (Ctrl+C)', this.instanceId) ||
7691
+ root.CodeLabRuntime.cancelWorkerExecution('SIGINT: Interrupted by user (Ctrl+C)', 'default')
7692
+ );
7693
+ } catch (err) {
7694
+ this.logger.debug('cancelWorkerExecution failed.', err);
7695
+ }
7367
7696
  }
7368
- const isCommandRunning = Boolean(this.isRunning || this._activeCommandAbortController);
7697
+ const isCommandRunning = Boolean(this.isRunning || this._activeCommandAbortController || cancelledWorker);
7369
7698
  const cwdShort = (this.cwd || '/workspace').replace(/^\/workspace\/?/, '') || '~';
7370
7699
  const promptLabel = this.inRepl ? '> ' : `codelab:${cwdShort}$`;
7371
7700
 
7372
7701
  if (isCommandRunning) {
7702
+ didInterrupt = true;
7373
7703
  if (this._activeCommandAbortController) {
7374
7704
  try {
7375
7705
  this._activeCommandAbortController.abort('SIGINT');
@@ -7379,25 +7709,21 @@ int main() {
7379
7709
  this._activeCommandAbortController = null;
7380
7710
  }
7381
7711
 
7382
- if (typeof root.CodeLabRuntime?.cancelWorkerExecution === 'function') {
7383
- try {
7384
- root.CodeLabRuntime.cancelWorkerExecution('SIGINT: Interrupted by user (Ctrl+C)', this.instanceId);
7385
- } catch (err) {
7386
- this.logger.debug('cancelWorkerExecution failed.', err);
7387
- }
7388
- }
7389
-
7390
7712
  this.isRunning = false;
7391
7713
  this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
7392
7714
  this._updateRunStateUI();
7393
7715
 
7394
7716
  this._flushTerminalStream();
7395
- this._pushTerminalLog({ type: 'stdout', text: '^C' });
7717
+ if (!fromXterm) {
7718
+ this._pushTerminalLog({ type: 'stdout', text: '^C' });
7719
+ }
7396
7720
  } else {
7397
7721
  if (this.inRepl) {
7398
7722
  this.inRepl = false;
7399
- this._pushTerminalLog({ type: 'stdout', text: '^C\nExiting REPL...' });
7400
- } else {
7723
+ if (!fromXterm) {
7724
+ this._pushTerminalLog({ type: 'stdout', text: '^C\nExiting REPL...' });
7725
+ }
7726
+ } else if (!fromXterm) {
7401
7727
  const currentInput = (this._ptyInputBeforeCursor || '') + (this._ptyInputAfterCursor || '');
7402
7728
  this._pushTerminalLog({ type: 'stdout', text: `${promptLabel} ${currentInput}^C` });
7403
7729
  }
@@ -7408,11 +7734,17 @@ int main() {
7408
7734
  this.replHistoryIdx = -1;
7409
7735
 
7410
7736
  this._renderDrawerBody();
7411
- const nextInput = this.container?.querySelector?.('#cl-repl-input');
7412
- if (nextInput && typeof nextInput.focus === 'function') {
7413
- nextInput.value = '';
7414
- nextInput.focus();
7737
+ const activeXterm = this._getActiveXtermEngine();
7738
+ if (activeXterm && typeof activeXterm.focus === 'function') {
7739
+ activeXterm.focus();
7740
+ } else {
7741
+ const nextInput = this.container?.querySelector?.('#cl-repl-input');
7742
+ if (nextInput && typeof nextInput.focus === 'function') {
7743
+ nextInput.value = '';
7744
+ nextInput.focus();
7745
+ }
7415
7746
  }
7747
+ return didInterrupt;
7416
7748
  }
7417
7749
 
7418
7750
  _updatePtyActiveLine() {
@@ -7816,8 +8148,8 @@ int main() {
7816
8148
  if (servers.length === 0) {
7817
8149
  serversHtml = `
7818
8150
  <div class="codelab-ports-empty">
7819
- <p style="margin:0 0 6px 0;font-weight:500;">No active port listeners</p>
7820
- <span style="font-size:12px;color:var(--cl-fg-muted);">
8151
+ <p class="cl-ui-body-p">No active port listeners</p>
8152
+ <span class="cl-ui-muted-note">
7821
8153
  Run an HTTP or WebSocket server in the terminal (e.g. <code>node server.js &amp;</code> or <code>bun run server.ts &amp;</code>) to bind a virtual port.
7822
8154
  </span>
7823
8155
  </div>
@@ -7940,7 +8272,7 @@ int main() {
7940
8272
  <div class="codelab-panel-section">
7941
8273
  <div class="codelab-section-title">
7942
8274
  <span>${CL_ICONS.send || ''} Mini HTTP Client</span>
7943
- <span style="font-size:11px;color:var(--cl-fg-muted);">Virtual Loopback (127.0.0.1)</span>
8275
+ <span class="cl-ui-muted-xs">Virtual Loopback (127.0.0.1)</span>
7944
8276
  </div>
7945
8277
  <div class="codelab-http-client">
7946
8278
  <div class="codelab-http-url-bar">
@@ -8089,7 +8421,7 @@ int main() {
8089
8421
 
8090
8422
  topologyHtml = `
8091
8423
  <div class="codelab-topo-bar">
8092
- <div class="codelab-topo-nodes">${nodePills || '<span style="font-size:11px;color:var(--cl-fg-muted);">No listening servers</span>'}</div>
8424
+ <div class="codelab-topo-nodes">${nodePills || '<span class="cl-ui-muted-xs">No listening servers</span>'}</div>
8093
8425
  ${edgePills ? `<div class="codelab-topo-edges">${edgePills}</div>` : ''}
8094
8426
  </div>
8095
8427
  `;
@@ -8141,8 +8473,8 @@ int main() {
8141
8473
  <td><span class="codelab-method-badge codelab-method-${(t.method || 'GET').toLowerCase()}">${escapeHtml(t.method || 'GET')}</span></td>
8142
8474
  <td class="codelab-net-path" title="${escapeHtml(t.url || '/')}">${escapeHtml(t.url || '/')}</td>
8143
8475
  <td><code>${escapeHtml(hopLabel)}</code></td>
8144
- <td style="white-space:nowrap;font-family:var(--cl-font-mono);font-size:11.5px;">${(t.durationMs || 0).toFixed(1)} ms</td>
8145
- <td style="white-space:nowrap;font-family:var(--cl-font-mono);font-size:11.5px;">${t.size != null ? t.size : 0} B</td>
8476
+ <td class="cl-ui-metric-cell">${(t.durationMs || 0).toFixed(1)} ms</td>
8477
+ <td class="cl-ui-metric-cell">${t.size != null ? t.size : 0} B</td>
8146
8478
  <td class="codelab-waterfall-cell">
8147
8479
  <div class="codelab-waterfall-track">
8148
8480
  <div class="codelab-waterfall-bar" style="width:${widthPct}%;"></div>
@@ -8257,7 +8589,7 @@ int main() {
8257
8589
  <option value="5xx" ${filter.status === '5xx' ? 'selected' : ''}>5xx / Network Fault</option>
8258
8590
  </select>
8259
8591
  <button type="button" class="codelab-btn" data-cl-action="clear-net-traces">Clear</button>
8260
- <span id="cl-net-count" style="margin-left:auto;font-size:11.5px;color:var(--cl-fg-muted);">${filtered.length} of ${traces.length} requests</span>
8592
+ <span id="cl-net-count" class="cl-ui-net-count">${filtered.length} of ${traces.length} requests</span>
8261
8593
  </div>
8262
8594
  <div class="codelab-net-main">
8263
8595
  <div class="codelab-net-table-container">
@@ -8339,8 +8671,8 @@ int main() {
8339
8671
  <td><span class="codelab-method-badge codelab-method-${(t.method || 'GET').toLowerCase()}">${escapeHtml(t.method || 'GET')}</span></td>
8340
8672
  <td class="codelab-net-path" title="${escapeHtml(t.url || '/')}">${escapeHtml(t.url || '/')}</td>
8341
8673
  <td><code>${escapeHtml(hopLabel)}</code></td>
8342
- <td style="white-space:nowrap;font-family:var(--cl-font-mono);font-size:11.5px;">${(t.durationMs || 0).toFixed(1)} ms</td>
8343
- <td style="white-space:nowrap;font-family:var(--cl-font-mono);font-size:11.5px;">${t.size != null ? t.size : 0} B</td>
8674
+ <td class="cl-ui-metric-cell">${(t.durationMs || 0).toFixed(1)} ms</td>
8675
+ <td class="cl-ui-metric-cell">${t.size != null ? t.size : 0} B</td>
8344
8676
  <td class="codelab-waterfall-cell">
8345
8677
  <div class="codelab-waterfall-track">
8346
8678
  <div class="codelab-waterfall-bar" style="width:${widthPct}%;"></div>
@@ -8504,6 +8836,269 @@ int main() {
8504
8836
  return this.dispatchHttpClientRequest();
8505
8837
  }
8506
8838
 
8839
+ get vfs() {
8840
+ return this.shell ? this.shell.vfs : null;
8841
+ }
8842
+
8843
+ _shouldUseXterm() {
8844
+ const mode = (this.options && this.options.terminalEngine) || 'auto';
8845
+ if (mode === 'dom') return false;
8846
+ if (!_wbComponents || typeof _wbComponents.canUseXtermInEnvironment !== 'function' || typeof _wbComponents.XtermTerminalEngine !== 'function') {
8847
+ return false;
8848
+ }
8849
+ return Boolean(_wbComponents.canUseXtermInEnvironment(this.container));
8850
+ }
8851
+
8852
+ _getActiveXtermEngine() {
8853
+ if (!(this._xtermEngines instanceof Map)) return null;
8854
+ const sessions = this._ensureTerminalSessions();
8855
+ const activeId = this._activeTerminalSessionId || (sessions[0] && sessions[0].id) || 'session-1';
8856
+ return this._xtermEngines.get(activeId) || null;
8857
+ }
8858
+
8859
+ _getOrCreateXtermEngineForSession(session, fontPx) {
8860
+ if (!this._shouldUseXterm() || !session) return null;
8861
+ if (!(this._xtermEngines instanceof Map)) {
8862
+ this._xtermEngines = new Map();
8863
+ }
8864
+ let eng = this._xtermEngines.get(session.id);
8865
+ const resolvedTheme = this._resolvedTheme();
8866
+ if (!eng) {
8867
+ eng = new _wbComponents.XtermTerminalEngine(null, {
8868
+ cwd: session.cwd || this.cwd || '/workspace',
8869
+ theme: resolvedTheme,
8870
+ fontSize: fontPx || 13,
8871
+ maxScrollback: this._getTerminalScrollback(),
8872
+ initialLogs: Array.isArray(session.logs) ? session.logs : [],
8873
+ onCommand: (cmd) => {
8874
+ if (this._activeTerminalSessionId !== session.id) {
8875
+ this.switchTerminalSession(session.id);
8876
+ }
8877
+ return this._handleReplCommand(cmd, { skipEcho: true });
8878
+ },
8879
+ onInterrupt: () => {
8880
+ if (this._activeTerminalSessionId !== session.id) {
8881
+ this.switchTerminalSession(session.id);
8882
+ }
8883
+ this._handleInterrupt({ fromXterm: true });
8884
+ },
8885
+ getCompletions: (buf, cur) => {
8886
+ const slice = String(buf || '').slice(0, typeof cur === 'number' ? cur : String(buf || '').length);
8887
+ const lastSpace = slice.lastIndexOf(' ');
8888
+ const tokenStart = lastSpace === -1 ? 0 : lastSpace + 1;
8889
+ const token = slice.slice(tokenStart);
8890
+ const matches = this._getCompletionCandidates(slice);
8891
+ return { tokenStart, token, matches };
8892
+ },
8893
+ onOpenFileLink: (relFile, lineNum, colNum) => {
8894
+ const clean = String(relFile || '').replace(/^\/workspace\//, '').replace(/^\/+/, '');
8895
+ if (clean && this.files && Object.prototype.hasOwnProperty.call(this.files, clean)) {
8896
+ this.openFile(clean);
8897
+ this._revealLineColInActiveEditor(lineNum || 1, colNum || 1);
8898
+ }
8899
+ }
8900
+ });
8901
+ session.logs = eng.logs;
8902
+ if (session.id === this._activeTerminalSessionId) {
8903
+ this.terminalLogs = eng.logs;
8904
+ }
8905
+ this._xtermEngines.set(session.id, eng);
8906
+ } else {
8907
+ if (typeof eng.setTheme === 'function') eng.setTheme(resolvedTheme);
8908
+ if (typeof eng.setFontSize === 'function') eng.setFontSize(fontPx || 13);
8909
+ if (typeof eng.setMaxScrollback === 'function') eng.setMaxScrollback(this._getTerminalScrollback());
8910
+ }
8911
+ return eng;
8912
+ }
8913
+
8914
+ _renderXtermTerminalBody(bodyEl, termFontPx) {
8915
+ if (!bodyEl || typeof document === 'undefined') return;
8916
+ const sessions = this._ensureTerminalSessions();
8917
+ const activeSession = sessions.find(s => s.id === this._activeTerminalSessionId) || sessions[0];
8918
+ if (!activeSession) return;
8919
+
8920
+ let leftSplit = null;
8921
+ let rightSplit = null;
8922
+ if (Array.isArray(this._splitTerminalSessionIds) && this._splitTerminalSessionIds.length >= 2) {
8923
+ const s0 = sessions.find(s => s.id === this._splitTerminalSessionIds[0]) || null;
8924
+ const s1 = sessions.find(s => s.id === this._splitTerminalSessionIds[1]) || null;
8925
+ if (s0 && s1 && s0.id !== s1.id && (activeSession.id === s0.id || activeSession.id === s1.id)) {
8926
+ leftSplit = s0;
8927
+ rightSplit = s1;
8928
+ } else if (!s0 || !s1 || s0.id === s1.id) {
8929
+ this._splitTerminalSessionIds = [];
8930
+ this._splitTerminalSessionId = null;
8931
+ }
8932
+ } else if (this._splitTerminalSessionId && this._splitTerminalSessionId !== activeSession.id) {
8933
+ const s1 = sessions.find(s => s.id === this._splitTerminalSessionId) || null;
8934
+ if (s1) {
8935
+ leftSplit = activeSession;
8936
+ rightSplit = s1;
8937
+ this._splitTerminalSessionIds = [activeSession.id, s1.id];
8938
+ } else {
8939
+ this._splitTerminalSessionId = null;
8940
+ }
8941
+ }
8942
+
8943
+ const isSplit = Boolean(leftSplit && rightSplit);
8944
+ const panes = isSplit ? [leftSplit, rightSplit] : [activeSession];
8945
+ const layoutKey = isSplit ? `${leftSplit.id}|${rightSplit.id}` : activeSession.id;
8946
+
8947
+ if (!this._xtermWrapEl || this._xtermWrapLayoutKey !== layoutKey) {
8948
+ if (this._xtermWrapEl && this._xtermWrapEl.parentNode) {
8949
+ try { this._xtermWrapEl.parentNode.removeChild(this._xtermWrapEl); } catch (_e) { void _e; }
8950
+ }
8951
+ const wrap = document.createElement('div');
8952
+ wrap.className = 'codelab-terminal-split-wrap codelab-terminal-split-grid' + (isSplit ? ' is-split' : '');
8953
+ bodyEl.innerHTML = '';
8954
+ bodyEl.appendChild(wrap);
8955
+ this._xtermWrapEl = wrap;
8956
+ this._xtermWrapLayoutKey = layoutKey;
8957
+
8958
+ for (const sess of panes) {
8959
+ const pane = document.createElement('div');
8960
+ pane.className = 'codelab-terminal-pane codelab-terminal-split-pane' + (sess.id === activeSession.id ? ' is-focused' : '');
8961
+ pane.setAttribute('data-session-id', sess.id);
8962
+ pane.addEventListener('pointerdown', () => {
8963
+ if (this._activeTerminalSessionId !== sess.id) {
8964
+ this._saveActiveTerminalSessionState();
8965
+ this._applyTerminalSessionState(sess);
8966
+ this._renderTerminalSessionsBar();
8967
+ this._renderXtermTerminalBody(bodyEl, termFontPx);
8968
+ }
8969
+ });
8970
+ wrap.appendChild(pane);
8971
+ const eng = this._getOrCreateXtermEngineForSession(sess, termFontPx);
8972
+ if (eng) {
8973
+ eng.mount(pane);
8974
+ }
8975
+ }
8976
+ } else if (this._xtermWrapEl.parentNode !== bodyEl) {
8977
+ bodyEl.innerHTML = '';
8978
+ bodyEl.appendChild(this._xtermWrapEl);
8979
+ }
8980
+
8981
+ if (this._xtermWrapEl) {
8982
+ this._xtermWrapEl.querySelectorAll('.codelab-terminal-pane').forEach(pane => {
8983
+ const sid = pane.getAttribute('data-session-id') || '';
8984
+ const isPaneActive = sid === activeSession.id;
8985
+ pane.classList.toggle('is-focused', isPaneActive);
8986
+ pane.querySelectorAll('[id]').forEach(el => {
8987
+ const baseId = el.getAttribute('data-cl-base-id') || el.id.replace(new RegExp(`-${sid}$`), '');
8988
+ el.setAttribute('data-cl-base-id', baseId);
8989
+ el.id = (!isSplit || isPaneActive) ? baseId : `${baseId}-${sid}`;
8990
+ });
8991
+ });
8992
+ }
8993
+
8994
+ const activeEng = this._getOrCreateXtermEngineForSession(activeSession, termFontPx);
8995
+ if (activeEng) {
8996
+ if (typeof activeEng.syncDomMirrorWithLogs === 'function') {
8997
+ activeEng.syncDomMirrorWithLogs(this.terminalLogs);
8998
+ }
8999
+ this.terminalLogs = activeEng.logs;
9000
+ activeSession.logs = activeEng.logs;
9001
+ if (typeof activeEng.setCwd === 'function') activeEng.setCwd(this.cwd || '/workspace');
9002
+ if (typeof activeEng.setReplMode === 'function') activeEng.setReplMode(Boolean(this.inRepl), this.replLang || 'node');
9003
+ if (typeof activeEng.setBusy === 'function') activeEng.setBusy(Boolean(this.isRunning));
9004
+ if (typeof activeEng.fit === 'function') activeEng.fit();
9005
+ }
9006
+ if (isSplit) {
9007
+ const otherSess = leftSplit.id === activeSession.id ? rightSplit : leftSplit;
9008
+ const otherEng = this._getOrCreateXtermEngineForSession(otherSess, termFontPx);
9009
+ if (otherEng && typeof otherEng.fit === 'function') otherEng.fit();
9010
+ }
9011
+ }
9012
+
9013
+ splitActiveTerminalSession() {
9014
+ const sessions = this._ensureTerminalSessions();
9015
+ if ((Array.isArray(this._splitTerminalSessionIds) && this._splitTerminalSessionIds.length >= 2) || this._splitTerminalSessionId) {
9016
+ this._splitTerminalSessionIds = [];
9017
+ this._splitTerminalSessionId = null;
9018
+ this._xtermWrapLayoutKey = '';
9019
+ this._renderDrawerBody();
9020
+ return null;
9021
+ }
9022
+ const primaryId = this._activeTerminalSessionId || (sessions[0] && sessions[0].id);
9023
+ let second = sessions.find(s => s.id !== primaryId);
9024
+ if (!second) {
9025
+ const newId = this.createTerminalSession();
9026
+ second = this._terminalSessions.find(s => s.id === newId);
9027
+ if (primaryId) {
9028
+ const orig = this._terminalSessions.find(s => s.id === primaryId);
9029
+ if (orig) this._applyTerminalSessionState(orig);
9030
+ }
9031
+ }
9032
+ if (second && primaryId) {
9033
+ this._splitTerminalSessionIds = [primaryId, second.id];
9034
+ this._splitTerminalSessionId = second.id;
9035
+ this._xtermWrapLayoutKey = '';
9036
+ this.switchDrawerTab('terminal', { ensureVisible: true, focus: true });
9037
+ return second.id;
9038
+ }
9039
+ return null;
9040
+ }
9041
+
9042
+ async _requestInteractiveTerminalStdin(promptText = '', signal = null) {
9043
+ if (this.customStdin && String(this.customStdin).length > 0) {
9044
+ const lines = String(this.customStdin).split(/\r?\n/);
9045
+ const first = lines.shift() ?? '';
9046
+ this.customStdin = lines.join('\n');
9047
+ return first;
9048
+ }
9049
+ const activeXterm = this._getActiveXtermEngine();
9050
+ if (activeXterm && typeof activeXterm.readLine === 'function') {
9051
+ if (!this.panelVisible || this.drawerTab !== 'terminal') {
9052
+ this.switchDrawerTab('terminal', { ensureVisible: true, focus: true });
9053
+ } else {
9054
+ activeXterm.focus();
9055
+ }
9056
+ return activeXterm.readLine(String(promptText ?? ''), { signal: signal || undefined });
9057
+ }
9058
+ if (this.ptyEngine && typeof this.ptyEngine.readLine === 'function' && this.ptyEngine.container) {
9059
+ return this.ptyEngine.readLine(String(promptText ?? ''), { signal: signal || undefined });
9060
+ }
9061
+ return null;
9062
+ }
9063
+
9064
+ _renderExplorerOutlineAndTimeline() {
9065
+ if (!this.container || typeof this.container.querySelector !== 'function') return;
9066
+ const outlineBody = this.container.querySelector('#cl-explorer-outline-body');
9067
+ const timelineBody = this.container.querySelector('#cl-explorer-timeline-body');
9068
+ if (outlineBody) {
9069
+ const activeFile = (this.activeTab === '__settings__' || this.activeTab === '__welcome__') ? null : this.activeFile;
9070
+ const code = (activeFile && this.files && typeof this.files[activeFile] === 'string') ? this.files[activeFile] : '';
9071
+ const symbols = (activeFile && code && _wbComponents && typeof _wbComponents.extractDocumentSymbols === 'function')
9072
+ ? _wbComponents.extractDocumentSymbols(activeFile, code)
9073
+ : [];
9074
+ if (!symbols || symbols.length === 0) {
9075
+ outlineBody.innerHTML = `<div class="codelab-explorer-section__empty">${activeFile ? 'No symbols found in active editor.' : 'Open a file to inspect symbols.'}</div>`;
9076
+ } else {
9077
+ outlineBody.innerHTML = symbols.slice(0, 80).map(sym => `
9078
+ <button type="button" class="codelab-outline-item" data-cl-action="reveal-symbol" data-symbol-file="${escapeHtml(sym.file || activeFile)}" data-symbol-line="${Number(sym.line || 1)}" data-symbol-col="${Number(sym.column || 1)}" title="${escapeHtml(sym.name)} (Ln ${Number(sym.line || 1)})">
9079
+ <span class="codelab-outline-item__kind codelab-outline-item__kind--${escapeHtml(sym.kind || 'variable')}">${escapeHtml((sym.kind || 'sym').slice(0, 1).toUpperCase())}</span>
9080
+ <span class="codelab-outline-item__name">${escapeHtml(sym.name)}</span>
9081
+ <span class="codelab-outline-item__line">:${Number(sym.line || 1)}</span>
9082
+ </button>
9083
+ `).join('');
9084
+ }
9085
+ }
9086
+ if (timelineBody) {
9087
+ const commits = typeof this.getGitLog === 'function' ? this.getGitLog(15) : [];
9088
+ if (!commits || commits.length === 0) {
9089
+ timelineBody.innerHTML = '<div class="codelab-explorer-section__empty">No Git commits recorded yet.</div>';
9090
+ } else {
9091
+ timelineBody.innerHTML = commits.map(c => `
9092
+ <div class="codelab-timeline-item" title="${escapeHtml(c.hash)} — ${escapeHtml(c.author || '')}">
9093
+ <span class="codelab-timeline-item__dot" aria-hidden="true"></span>
9094
+ <span class="codelab-timeline-item__msg">${escapeHtml(c.message)}</span>
9095
+ <span class="codelab-timeline-item__hash">${escapeHtml(String(c.hash || '').slice(0, 7))}</span>
9096
+ </div>
9097
+ `).join('');
9098
+ }
9099
+ }
9100
+ }
9101
+
8507
9102
  switchDrawerTab(tab, opts = {}) {
8508
9103
  if (!tab) return;
8509
9104
  if (!opts || !opts.fromConfig) {
@@ -8538,8 +9133,13 @@ int main() {
8538
9133
  }
8539
9134
  this._renderDrawerBody();
8540
9135
  if (opts && opts.focus && this.drawerTab === 'terminal' && this.container) {
8541
- const termInput = this.container.querySelector('#cl-repl-input');
8542
- if (termInput && typeof termInput.focus === 'function') termInput.focus();
9136
+ const activeXterm = this._getActiveXtermEngine();
9137
+ if (activeXterm && typeof activeXterm.focus === 'function') {
9138
+ activeXterm.focus();
9139
+ } else {
9140
+ const termInput = this.container.querySelector('#cl-repl-input');
9141
+ if (termInput && typeof termInput.focus === 'function') termInput.focus();
9142
+ }
8543
9143
  }
8544
9144
  if (!opts || (!opts.fromConfig && !opts.skipSave)) {
8545
9145
  this._saveState();
@@ -8548,6 +9148,11 @@ int main() {
8548
9148
 
8549
9149
  setPanelVisible(visible, opts = {}) {
8550
9150
  const next = Boolean(visible);
9151
+ if (!next && this.panelHeight >= 100) {
9152
+ this._savedPanelHeight = this.panelHeight;
9153
+ } else if (next && (!this.panelHeight || this.panelHeight < 100)) {
9154
+ this.panelHeight = Math.max(140, this._savedPanelHeight || 220);
9155
+ }
8551
9156
  this.panelVisible = next;
8552
9157
  this.drawerCollapsed = !next;
8553
9158
  if (!next) {
@@ -8557,7 +9162,11 @@ int main() {
8557
9162
  const shell = this.container.querySelector('.codelab');
8558
9163
  if (shell && shell.classList) {
8559
9164
  shell.classList.toggle('panel-collapsed', !next);
8560
- if (!next) shell.classList.remove('panel-maximized');
9165
+ if (!next) {
9166
+ shell.classList.remove('panel-maximized');
9167
+ } else if (this.panelHeight >= 100) {
9168
+ this._setShellCssVar(shell, '--cl-drawer-height', `${this.panelHeight}px`);
9169
+ }
8561
9170
  }
8562
9171
  const drawer = this.container.querySelector('#cl-drawer');
8563
9172
  if (drawer && drawer.classList) {
@@ -8568,16 +9177,25 @@ int main() {
8568
9177
  toggleBtn.classList.toggle('active', next);
8569
9178
  toggleBtn.setAttribute('aria-pressed', String(next));
8570
9179
  }
9180
+ const statusToggleBtn = this.container.querySelector('#cl-status-panel-toggle');
9181
+ if (statusToggleBtn) {
9182
+ statusToggleBtn.classList.toggle('active', next);
9183
+ statusToggleBtn.setAttribute('aria-pressed', String(next));
9184
+ }
8571
9185
  }
8572
9186
  if (this.editor && typeof this.editor.layout === 'function') {
8573
9187
  this.editor.layout();
8574
9188
  setTimeout(() => {
8575
9189
  if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
9190
+ if (next) {
9191
+ const activeXterm = this._getActiveXtermEngine();
9192
+ if (activeXterm && typeof activeXterm.fit === 'function') activeXterm.fit();
9193
+ }
8576
9194
  }, 50);
8577
9195
  }
8578
9196
  if (!opts || !opts.skipRender) {
8579
9197
  if (next) this._renderDrawerBody();
8580
- this._saveState();
9198
+ if (!opts || !opts.skipSave) this._saveState();
8581
9199
  }
8582
9200
  return this.panelVisible;
8583
9201
  }
@@ -8611,6 +9229,8 @@ int main() {
8611
9229
  this.editor.layout();
8612
9230
  setTimeout(() => {
8613
9231
  if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
9232
+ const activeXterm = this._getActiveXtermEngine();
9233
+ if (activeXterm && typeof activeXterm.fit === 'function') activeXterm.fit();
8614
9234
  }, 50);
8615
9235
  }
8616
9236
  this._saveState();
@@ -8620,7 +9240,7 @@ int main() {
8620
9240
  toggleTerminal() {
8621
9241
  if (this.panelVisible && this.drawerTab === 'terminal') {
8622
9242
  this.setPanelVisible(false);
8623
- if (this.editor && typeof this.editor.focus === 'function' && this.activeTab !== '__settings__') {
9243
+ if (this.editor && typeof this.editor.focus === 'function' && this.activeTab !== '__settings__' && this.activeTab !== '__welcome__') {
8624
9244
  this.editor.focus();
8625
9245
  }
8626
9246
  return false;
@@ -10033,6 +10653,40 @@ int main() {
10033
10653
  loadMonaco(this.monacoUrl).then(m => {
10034
10654
  if (this._destroyed || !this.container) return;
10035
10655
  this.monaco = m;
10656
+ const wsPrefix = '/workspace-' + encodeURIComponent(this.instanceId);
10657
+ if (_wbComponents && typeof _wbComponents.initializeMonacoIntelligence === 'function') {
10658
+ try {
10659
+ _wbComponents.initializeMonacoIntelligence(m, () => this.files || {});
10660
+ } catch (err) {
10661
+ this.logger.debug('initializeMonacoIntelligence skipped.', err);
10662
+ }
10663
+ }
10664
+ if (_wbComponents && typeof _wbComponents.syncTsConfigToMonaco === 'function') {
10665
+ try {
10666
+ _wbComponents.syncTsConfigToMonaco(m, this.files || {}, 'file://' + wsPrefix);
10667
+ } catch (err) {
10668
+ this.logger.debug('syncTsConfigToMonaco skipped.', err);
10669
+ }
10670
+ }
10671
+ if (Array.isArray(this._monacoReadyHooks)) {
10672
+ for (const fn of this._monacoReadyHooks) {
10673
+ if (typeof fn === 'function') {
10674
+ try {
10675
+ fn(m);
10676
+ } catch (err) {
10677
+ this.logger.debug('Extension monacoReadyHook threw.', err);
10678
+ }
10679
+ }
10680
+ }
10681
+ }
10682
+ if (!this._ataController && _wbComponents && typeof _wbComponents.WorkspaceAtaController === 'function') {
10683
+ try {
10684
+ this._ataController = new _wbComponents.WorkspaceAtaController(m);
10685
+ this._ataController.scheduleScan(this.files || {});
10686
+ } catch (err) {
10687
+ this.logger.debug('WorkspaceAtaController init skipped.', err);
10688
+ }
10689
+ }
10036
10690
  if (this._diagnosticsStore && typeof this._diagnosticsStore.setFileDiagnostics === 'function' && this.files) {
10037
10691
  for (const fn of Object.keys(this.files)) {
10038
10692
  if (/\.(?:m?js|cjs|ts)$/i.test(fn)) {
@@ -10093,11 +10747,13 @@ int main() {
10093
10747
  }
10094
10748
 
10095
10749
  const resolvedInitTheme = this._resolvedTheme();
10096
- const initMonacoTheme = resolvedInitTheme === 'light'
10097
- ? 'codelab-light'
10098
- : resolvedInitTheme === 'high-contrast'
10099
- ? 'codelab-hc-dark'
10100
- : 'codelab-dark';
10750
+ const initMonacoTheme = (_wbComponents && typeof _wbComponents.getMonacoThemeName === 'function')
10751
+ ? _wbComponents.getMonacoThemeName(resolvedInitTheme, m)
10752
+ : (resolvedInitTheme === 'light'
10753
+ ? 'codelab-light'
10754
+ : resolvedInitTheme === 'high-contrast'
10755
+ ? 'codelab-hc-dark'
10756
+ : 'codelab-dark');
10101
10757
 
10102
10758
  // Create models for all code files
10103
10759
  this._syncAllModels();
@@ -10120,9 +10776,25 @@ int main() {
10120
10776
  smoothScrolling: true,
10121
10777
  cursorBlinking: 'smooth',
10122
10778
  renderLineHighlight: 'all',
10123
- bracketPairColorization: { enabled: true }
10779
+ bracketPairColorization: { enabled: true },
10780
+ glyphMargin: false,
10781
+ folding: true
10124
10782
  });
10125
10783
 
10784
+ if (_wbComponents && typeof _wbComponents.registerCrossFileEditorOpener === 'function') {
10785
+ this._editorOpenerDisposable = _wbComponents.registerCrossFileEditorOpener(m, (relFile, ln, col) => {
10786
+ if (this.files && Object.prototype.hasOwnProperty.call(this.files, relFile)) {
10787
+ this.openFile(relFile);
10788
+ this._revealLineColInActiveEditor(ln || 1, col || 1);
10789
+ return true;
10790
+ }
10791
+ return false;
10792
+ }, wsPrefix);
10793
+ }
10794
+ if (_wbComponents && typeof _wbComponents.attachAutoCloseTagBehavior === 'function') {
10795
+ this._autoCloseTagDisposable = _wbComponents.attachAutoCloseTagBehavior(m, this.editor);
10796
+ }
10797
+
10126
10798
  this._applyConfigurationChanges(null);
10127
10799
 
10128
10800
  if (typeof this.editor.onDidBlurEditorWidget === 'function') {
@@ -10206,15 +10878,21 @@ int main() {
10206
10878
  if (liveFallbackWrap) liveFallbackWrap.style.display = 'none';
10207
10879
  this._syncActiveFileToView();
10208
10880
 
10209
- // Watch theme changes on <html>
10210
- if (typeof MutationObserver !== 'undefined') {
10881
+ // Watch theme changes on <html> only when document theme sync is active
10882
+ const observeDocTheme = Boolean(
10883
+ (this.options && (this.options.fullbleed || this.options.syncDocumentTheme)) ||
10884
+ (typeof document !== 'undefined' && document.documentElement && document.documentElement.hasAttribute('data-theme'))
10885
+ );
10886
+ if (typeof MutationObserver !== 'undefined' && observeDocTheme && typeof document !== 'undefined' && document.documentElement) {
10211
10887
  this._themeObserver = new MutationObserver(() => {
10212
10888
  const rt = this._resolvedTheme();
10213
- const targetMonacoTheme = rt === 'light'
10214
- ? 'codelab-light'
10215
- : rt === 'high-contrast'
10216
- ? 'codelab-hc-dark'
10217
- : 'codelab-dark';
10889
+ const targetMonacoTheme = (_wbComponents && typeof _wbComponents.getMonacoThemeName === 'function')
10890
+ ? _wbComponents.getMonacoThemeName(rt, m)
10891
+ : (rt === 'light'
10892
+ ? 'codelab-light'
10893
+ : rt === 'high-contrast'
10894
+ ? 'codelab-hc-dark'
10895
+ : 'codelab-dark');
10218
10896
  m.editor.setTheme(targetMonacoTheme);
10219
10897
  });
10220
10898
  this._themeObserver.observe(document.documentElement, {
@@ -10222,7 +10900,8 @@ int main() {
10222
10900
  attributeFilter: ['data-theme']
10223
10901
  });
10224
10902
  }
10225
- }).catch(() => {
10903
+ }).catch((err) => {
10904
+ void err;
10226
10905
  if (this._destroyed || !this.container) return;
10227
10906
  // Fallback editor remains visible if offline / CDN blocked
10228
10907
  const liveFallbackWrap = this.container.querySelector('#cl-fallback-wrap');
@@ -10257,6 +10936,20 @@ int main() {
10257
10936
  if (cleanRel.startsWith('.codelab/') && !this._syncingWorkspaceSettingsFile) {
10258
10937
  this._syncDotCodelabConfig({ isInitialMount: false });
10259
10938
  }
10939
+ if (this.monaco && (cleanRel === 'tsconfig.json' || cleanRel === 'jsconfig.json') && _wbComponents && typeof _wbComponents.syncTsConfigToMonaco === 'function') {
10940
+ try {
10941
+ _wbComponents.syncTsConfigToMonaco(this.monaco, this.files || {}, 'file:///workspace-' + encodeURIComponent(this.instanceId));
10942
+ } catch (err) {
10943
+ this.logger.debug('Live tsconfig sync skipped.', err);
10944
+ }
10945
+ }
10946
+ if (this._ataController && (cleanRel === 'package.json' || /\.(?:m?js|cjs|jsx|ts|tsx)$/i.test(cleanRel))) {
10947
+ try {
10948
+ this._ataController.scheduleScan(this.files || {});
10949
+ } catch (err) {
10950
+ this.logger.debug('ATA scan skipped.', err);
10951
+ }
10952
+ }
10260
10953
  if (this._lintDebounceTimer) {
10261
10954
  clearTimeout(this._lintDebounceTimer);
10262
10955
  }
@@ -10269,6 +10962,10 @@ int main() {
10269
10962
  if (this.activeSidebarView === 'scm' && typeof this._renderScmSidebar === 'function') {
10270
10963
  this._renderScmSidebar();
10271
10964
  }
10965
+ this._updateEditorGitGutter();
10966
+ if (this.activeSidebarView === 'explorer' && typeof this._renderExplorerOutlineAndTimeline === 'function') {
10967
+ this._renderExplorerOutlineAndTimeline();
10968
+ }
10272
10969
  const allowPreviewReload = !this.configuration || this.configuration.get('preview.autoReload', true) !== false;
10273
10970
  if (allowPreviewReload && (this.drawerTab === 'preview' || (this.previewState && this.previewState.dockMode === 'split')) && this.previewState && this.previewState.port) {
10274
10971
  if (this._previewReloadTimer) {
@@ -10307,7 +11004,8 @@ int main() {
10307
11004
  if (!this.monaco || !this.monaco.editor || typeof this.monaco.editor.getModelMarkers !== 'function') return;
10308
11005
  this._ensureDiagnosticsStore();
10309
11006
  if (!this._diagnosticsStore || typeof this._diagnosticsStore.setFileDiagnostics !== 'function') return;
10310
- const prefix = `file:///${encodeURIComponent(this.instanceId)}/`;
11007
+ const wsPrefix = '/workspace-' + encodeURIComponent(this.instanceId);
11008
+ const prefix = `file://${wsPrefix}/`;
10311
11009
  for (const [filename, model] of this.models.entries()) {
10312
11010
  const uri = model && model.uri ? model.uri : null;
10313
11011
  let markers = [];
@@ -10343,31 +11041,41 @@ int main() {
10343
11041
 
10344
11042
  _getOrCreateModel(filename) {
10345
11043
  if (!filename || !this.monaco || !this.monaco.editor) return null;
10346
- const uriParser = (this.monaco.Uri && typeof this.monaco.Uri.parse === 'function')
10347
- ? this.monaco.Uri
10348
- : (this.monaco.editor.Uri && typeof this.monaco.editor.Uri.parse === 'function')
10349
- ? this.monaco.editor.Uri
10350
- : null;
10351
- const rawUri = `file:///${encodeURIComponent(this.instanceId)}/${filename}`;
10352
- const uri = uriParser ? uriParser.parse(rawUri) : { toString: () => rawUri };
11044
+ const wsPrefix = '/workspace-' + encodeURIComponent(this.instanceId);
11045
+ const cleanRel = String(filename).replace(/^\/+/, '');
11046
+ let uri = null;
11047
+ if (_wbComponents && typeof _wbComponents.toWorkspaceModelUri === 'function') {
11048
+ uri = _wbComponents.toWorkspaceModelUri(this.monaco, cleanRel, wsPrefix);
11049
+ }
11050
+ if (!uri) {
11051
+ const uriParser = (this.monaco.Uri && typeof this.monaco.Uri.parse === 'function')
11052
+ ? this.monaco.Uri
11053
+ : (this.monaco.editor.Uri && typeof this.monaco.editor.Uri.parse === 'function')
11054
+ ? this.monaco.editor.Uri
11055
+ : null;
11056
+ const rawUri = `file://${wsPrefix}/${cleanRel}`;
11057
+ uri = uriParser ? uriParser.parse(rawUri) : { toString: () => rawUri };
11058
+ }
10353
11059
  let model = typeof this.monaco.editor.getModel === 'function' ? this.monaco.editor.getModel(uri) : null;
10354
- const lang = /\.(cpp|cc|cxx|hpp|h)$/i.test(filename)
10355
- ? 'cpp'
10356
- : /\.py$/i.test(filename)
10357
- ? 'python'
10358
- : /\.sql$/i.test(filename)
10359
- ? 'sql'
10360
- : filename.endsWith('.ts')
10361
- ? 'typescript'
10362
- : filename.endsWith('.json')
10363
- ? 'json'
10364
- : filename.endsWith('.html')
10365
- ? 'html'
10366
- : filename.endsWith('.css')
10367
- ? 'css'
10368
- : filename.endsWith('.md')
10369
- ? 'markdown'
10370
- : 'javascript';
11060
+ const lang = (_wbComponents && typeof _wbComponents.getMonacoLanguageForFile === 'function')
11061
+ ? _wbComponents.getMonacoLanguageForFile(filename, this.lang)
11062
+ : (/\.(cpp|cc|cxx|hpp|h)$/i.test(filename)
11063
+ ? 'cpp'
11064
+ : /\.py$/i.test(filename)
11065
+ ? 'python'
11066
+ : /\.sql$/i.test(filename)
11067
+ ? 'sql'
11068
+ : /\.(?:ts|tsx|mts|cts)$/i.test(filename)
11069
+ ? 'typescript'
11070
+ : filename.endsWith('.json')
11071
+ ? 'json'
11072
+ : filename.endsWith('.html')
11073
+ ? 'html'
11074
+ : filename.endsWith('.css')
11075
+ ? 'css'
11076
+ : filename.endsWith('.md')
11077
+ ? 'markdown'
11078
+ : 'javascript');
10371
11079
  const configuredTabSize = this.configuration
10372
11080
  ? Math.max(1, Math.min(8, Number(this.configuration.get('editor.tabSize', 2)) || 2))
10373
11081
  : 2;
@@ -10413,22 +11121,218 @@ int main() {
10413
11121
  return model;
10414
11122
  }
10415
11123
 
10416
- _syncAllModels() {
10417
- if (!this.monaco) return;
10418
- const activeSet = new Set(Object.keys(this.files || {}));
10419
- for (const [filename, model] of Array.from(this.models.entries())) {
10420
- if (!activeSet.has(filename)) {
10421
- if (model && typeof model.dispose === 'function') {
10422
- try { model.dispose(); } catch (err) { this.logger.debug('Stale model dispose skipped.', err); }
11124
+ _syncAllModels() {
11125
+ if (!this.monaco) return;
11126
+ const activeSet = new Set(Object.keys(this.files || {}));
11127
+ for (const [filename, model] of Array.from(this.models.entries())) {
11128
+ if (!activeSet.has(filename)) {
11129
+ if (model && typeof model.dispose === 'function') {
11130
+ try { model.dispose(); } catch (err) { this.logger.debug('Stale model dispose skipped.', err); }
11131
+ }
11132
+ this.models.delete(filename);
11133
+ }
11134
+ }
11135
+ for (const filename of activeSet) {
11136
+ const content = String(this.files[filename] || '');
11137
+ if (content.length <= 2 * 1024 * 1024 && !content.includes('\x00')) {
11138
+ this._getOrCreateModel(filename);
11139
+ }
11140
+ }
11141
+ if (this.monaco && _wbComponents && typeof _wbComponents.syncTsConfigToMonaco === 'function') {
11142
+ try {
11143
+ _wbComponents.syncTsConfigToMonaco(this.monaco, this.files || {}, 'file:///workspace-' + encodeURIComponent(this.instanceId));
11144
+ } catch (err) {
11145
+ this.logger.debug('syncTsConfigToMonaco after syncAllModels skipped.', err);
11146
+ }
11147
+ }
11148
+ if (this._ataController && typeof this._ataController.scheduleScan === 'function') {
11149
+ try {
11150
+ this._ataController.scheduleScan(this.files || {});
11151
+ } catch (err) {
11152
+ this.logger.debug('ATA scan after syncAllModels skipped.', err);
11153
+ }
11154
+ }
11155
+ }
11156
+
11157
+ _updateEditorGitGutter() {
11158
+ if (!this.editor || !this.monaco || !this.activeFile || this.activeTab === '__settings__' || this.activeTab === '__welcome__') {
11159
+ return;
11160
+ }
11161
+ const scmMod = root.CodeLabScm;
11162
+ const gs = this._getGitState();
11163
+ if (!scmMod || typeof scmMod.computeGitGutterChanges !== 'function' || !gs || !gs.initialized) {
11164
+ if (this._gitGutterDecorations && typeof this._gitGutterDecorations.clear === 'function') {
11165
+ try { this._gitGutterDecorations.clear(); } catch (_err) { void _err; }
11166
+ }
11167
+ return;
11168
+ }
11169
+ const headMap = gs.headFiles || gs.headSnapshot || {};
11170
+ const hasHead = Object.prototype.hasOwnProperty.call(headMap, this.activeFile);
11171
+ const headText = hasHead ? String(headMap[this.activeFile] ?? '') : '';
11172
+ const curText = String(this.files[this.activeFile] ?? '');
11173
+ const changes = hasHead
11174
+ ? scmMod.computeGitGutterChanges(headText, curText)
11175
+ : (curText.length > 0 ? [{ type: 'added', startLine: 1, endLine: Math.max(1, curText.split('\n').length) }] : []);
11176
+ const RangeCtor = this.monaco.Range;
11177
+ if (typeof RangeCtor !== 'function') return;
11178
+ const decorations = (changes || []).map((ch) => {
11179
+ const cls = ch.type === 'added'
11180
+ ? 'codelab-git-gutter-added'
11181
+ : ch.type === 'deleted'
11182
+ ? 'codelab-git-gutter-deleted'
11183
+ : 'codelab-git-gutter-modified';
11184
+ const sLine = Math.max(1, Number(ch.startLine || 1));
11185
+ const eLine = Math.max(sLine, Number(ch.endLine || sLine));
11186
+ return {
11187
+ range: new RangeCtor(sLine, 1, eLine, 1),
11188
+ options: {
11189
+ isWholeLine: true,
11190
+ linesDecorationsClassName: cls
11191
+ }
11192
+ };
11193
+ });
11194
+ if (typeof this.editor.createDecorationsCollection === 'function') {
11195
+ if (!this._gitGutterDecorations) {
11196
+ this._gitGutterDecorations = this.editor.createDecorationsCollection(decorations);
11197
+ } else {
11198
+ this._gitGutterDecorations.set(decorations);
11199
+ }
11200
+ } else if (typeof this.editor.deltaDecorations === 'function') {
11201
+ this._gitGutterDecorationIds = this.editor.deltaDecorations(this._gitGutterDecorationIds || [], decorations);
11202
+ }
11203
+ }
11204
+
11205
+ openWelcomeTab() {
11206
+ this._activeScmDiffFile = null;
11207
+ this.welcomeTabOpen = true;
11208
+ this.activeTab = '__welcome__';
11209
+ this._syncActiveFileToView();
11210
+ }
11211
+
11212
+ closeWelcomeTab() {
11213
+ if (!this.welcomeTabOpen && this.activeTab !== '__welcome__') return;
11214
+ this.welcomeTabOpen = false;
11215
+ const nextFile = (this.activeFile && Array.isArray(this.openTabs) && this.openTabs.includes(this.activeFile))
11216
+ ? this.activeFile
11217
+ : (Array.isArray(this.openTabs) && this.openTabs.length > 0 ? this.openTabs[0] : null);
11218
+ this.activeFile = nextFile;
11219
+ this.activeTab = this.settingsTabOpen ? '__settings__' : nextFile;
11220
+ this._syncActiveFileToView();
11221
+ }
11222
+
11223
+ _renderWelcomeHost(welcomeHost) {
11224
+ if (!welcomeHost) return;
11225
+ const wsMod = this._getWorkspaceStorageMod();
11226
+ const recentList = (wsMod && typeof wsMod.listWorkspaces === 'function') ? wsMod.listWorkspaces().slice(0, 5) : [];
11227
+ const templates = (this.options && Array.isArray(this.options.welcomeTemplates))
11228
+ ? this.options.welcomeTemplates
11229
+ : [];
11230
+ const templatesHtml = templates.length > 0
11231
+ ? `
11232
+ <div class="codelab-welcome__section">
11233
+ <h3 class="codelab-welcome__heading">Start with a Template</h3>
11234
+ <div class="codelab-welcome__templates">
11235
+ ${templates.map((tpl) => `
11236
+ <button type="button" class="codelab-welcome__card" data-cl-action="welcome-load-template" data-demo="${escapeHtml(tpl.id || '')}">
11237
+ <span class="codelab-welcome__card-badge">${escapeHtml(tpl.badge || 'Stack')}</span>
11238
+ <strong class="codelab-welcome__card-title">${escapeHtml(tpl.title || tpl.id || 'Template')}</strong>
11239
+ <span class="codelab-welcome__card-desc">${escapeHtml(tpl.description || '')}</span>
11240
+ </button>
11241
+ `).join('')}
11242
+ </div>
11243
+ </div>
11244
+ `
11245
+ : '';
11246
+ const recentHtml = recentList.length > 0
11247
+ ? recentList.map((ws) => `
11248
+ <button type="button" class="codelab-welcome__link" data-cl-action="welcome-open-recent" data-workspace-id="${escapeHtml(ws.labId)}">
11249
+ <span>${escapeHtml(ws.title || ws.labId)}</span>
11250
+ <span class="codelab-welcome__link-meta">${escapeHtml(ws.repo || ws.labId)}</span>
11251
+ </button>
11252
+ `).join('')
11253
+ : '<div class="codelab-welcome__muted">No recent workspaces yet.</div>';
11254
+
11255
+ welcomeHost.innerHTML = `
11256
+ <div class="codelab-welcome__inner">
11257
+ <header class="codelab-welcome__hero">
11258
+ <div class="codelab-welcome__title-row">
11259
+ <span class="codelab-welcome__logo" aria-hidden="true">${CL_ICONS.code || ''}</span>
11260
+ <div>
11261
+ <h2 class="codelab-welcome__title">CodeLab Studio</h2>
11262
+ <p class="codelab-welcome__subtitle">Browser-native IDE — Node.js v22 Worker, TypeScript 5, Python 3.12, C++20 WASI, SQL &amp; Git</p>
11263
+ </div>
11264
+ </div>
11265
+ </header>
11266
+ <div class="codelab-welcome__grid">
11267
+ <div class="codelab-welcome__col">
11268
+ <div class="codelab-welcome__section">
11269
+ <h3 class="codelab-welcome__heading">Start</h3>
11270
+ <div class="codelab-welcome__actions">
11271
+ <button type="button" class="codelab-welcome__action" data-cl-action="welcome-new-file">
11272
+ ${CL_ICONS.newFile || ''}<span>New File...</span><kbd>⌘N</kbd>
11273
+ </button>
11274
+ <button type="button" class="codelab-welcome__action" data-cl-action="welcome-clone-repo">
11275
+ ${CL_ICONS.gitBranch || ''}<span>Clone Git Repository...</span><kbd>⌘⇧G</kbd>
11276
+ </button>
11277
+ <button type="button" class="codelab-welcome__action" data-cl-action="new-blank-workspace">
11278
+ ${CL_ICONS.newFolder || ''}<span>New Blank Workspace...</span>
11279
+ </button>
11280
+ <button type="button" class="codelab-welcome__action" data-cl-action="command-palette">
11281
+ ${CL_ICONS.search || ''}<span>Show All Commands...</span><kbd>⌘⇧P</kbd>
11282
+ </button>
11283
+ </div>
11284
+ </div>
11285
+ <div class="codelab-welcome__section">
11286
+ <h3 class="codelab-welcome__heading">Clone GitHub Repository</h3>
11287
+ <form class="codelab-welcome__clone-bar" data-cl-welcome-clone-form>
11288
+ <input data-cl-welcome-repo-input class="codelab-welcome__clone-input" type="text" placeholder="owner/repo or https://github.com/owner/repo" autocomplete="off" spellcheck="false" aria-label="GitHub repository URL or owner/repo" />
11289
+ <button data-cl-welcome-clone-btn type="submit" class="codelab-btn codelab-btn--primary">Clone</button>
11290
+ </form>
11291
+ </div>
11292
+ <div class="codelab-welcome__section">
11293
+ <h3 class="codelab-welcome__heading">Recent</h3>
11294
+ <div class="codelab-welcome__recent">${recentHtml}</div>
11295
+ </div>
11296
+ </div>
11297
+ <div class="codelab-welcome__col">
11298
+ ${templatesHtml || `
11299
+ <div class="codelab-welcome__section">
11300
+ <h3 class="codelab-welcome__heading">Walkthroughs</h3>
11301
+ <div class="codelab-welcome__walkthroughs">
11302
+ <div class="codelab-welcome__walkthrough">
11303
+ <strong>Full IntelliSense &amp; Cross-File Navigation</strong>
11304
+ <span>Press <kbd>F12</kbd> on any imported function or class to jump directly across workspace files.</span>
11305
+ </div>
11306
+ <div class="codelab-welcome__walkthrough">
11307
+ <strong>Integrated xterm.js &amp; POSIX Shell</strong>
11308
+ <span>Press <kbd>⌃\`</kbd> or <kbd>⌘J</kbd> to toggle the panel, split terminals, or run <code>node</code>, <code>python3</code>, <code>clang++</code>, and <code>git</code>.</span>
11309
+ </div>
11310
+ <div class="codelab-welcome__walkthrough">
11311
+ <strong>Real Git &amp; Side-by-Side Diffs</strong>
11312
+ <span>Stage hunks, switch branches, stash changes, and inspect side-by-side diffs in Source Control.</span>
11313
+ </div>
11314
+ </div>
11315
+ </div>
11316
+ `}
11317
+ </div>
11318
+ </div>
11319
+ </div>
11320
+ `;
11321
+ const cloneForm = welcomeHost.querySelector('[data-cl-welcome-clone-form]');
11322
+ if (cloneForm) {
11323
+ cloneForm.addEventListener('submit', (ev) => {
11324
+ ev.preventDefault();
11325
+ const inp = welcomeHost.querySelector('[data-cl-welcome-repo-input]');
11326
+ const val = inp ? String(inp.value || '').trim() : '';
11327
+ if (!val) {
11328
+ this.openCloneDialog();
11329
+ return;
10423
11330
  }
10424
- this.models.delete(filename);
10425
- }
10426
- }
10427
- for (const filename of activeSet) {
10428
- const content = String(this.files[filename] || '');
10429
- if (content.length <= 2 * 1024 * 1024 && !content.includes('\x00')) {
10430
- this._getOrCreateModel(filename);
10431
- }
11331
+ this.closeWelcomeTab();
11332
+ this.cloneRepo(val, { intoRoot: true, force: true }).catch((err) => {
11333
+ this.logger.warn('Welcome clone failed.', err);
11334
+ });
11335
+ });
10432
11336
  }
10433
11337
  }
10434
11338
 
@@ -10439,9 +11343,42 @@ int main() {
10439
11343
  const fallbackEl = this.container.querySelector('#cl-fallback-editor');
10440
11344
  const mdPreview = this.container.querySelector('#cl-md-preview');
10441
11345
  const settingsHost = this.container.querySelector('#cl-settings-host');
11346
+ const welcomeHost = this.container.querySelector('#cl-welcome-host');
10442
11347
  const inlineDiffHost = this.container.querySelector('#cl-inline-diff-container');
10443
11348
  const emptyEl = this.container.querySelector('#cl-empty-editor');
10444
11349
 
11350
+ // Non-destructive Welcome Tab
11351
+ if (this.welcomeTabOpen && this.activeTab === '__welcome__') {
11352
+ this._activeScmDiffFile = null;
11353
+ if (monacoHost) monacoHost.style.display = 'none';
11354
+ if (sqlHost) sqlHost.style.display = 'none';
11355
+ if (fallbackWrap) fallbackWrap.style.display = 'none';
11356
+ if (mdPreview) mdPreview.style.display = 'none';
11357
+ if (emptyEl) emptyEl.style.display = 'none';
11358
+ if (settingsHost) {
11359
+ settingsHost.hidden = true;
11360
+ if (settingsHost.style) settingsHost.style.display = 'none';
11361
+ }
11362
+ if (inlineDiffHost) {
11363
+ inlineDiffHost.hidden = true;
11364
+ if (inlineDiffHost.style) inlineDiffHost.style.display = 'none';
11365
+ }
11366
+ if (welcomeHost) {
11367
+ welcomeHost.hidden = false;
11368
+ if (welcomeHost.style) welcomeHost.style.display = 'block';
11369
+ this._renderWelcomeHost(welcomeHost);
11370
+ }
11371
+ this._renderFileLists();
11372
+ this._renderBreadcrumbs();
11373
+ this._updateStatusBar();
11374
+ return;
11375
+ }
11376
+
11377
+ if (welcomeHost) {
11378
+ welcomeHost.hidden = true;
11379
+ if (welcomeHost.style) welcomeHost.style.display = 'none';
11380
+ }
11381
+
10445
11382
  // Non-destructive Settings Tab: hide code surfaces via display:none WITHOUT calling editor.setModel(null) or disposing!
10446
11383
  if (this.settingsTabOpen && this.activeTab === '__settings__') {
10447
11384
  this._activeScmDiffFile = null;
@@ -10490,7 +11427,7 @@ int main() {
10490
11427
  actSettingsBtn.setAttribute('aria-pressed', 'false');
10491
11428
  }
10492
11429
 
10493
- // Non-destructive Source Control Inline Diff: hide sibling editor hosts via display:none WITHOUT mutating models/buffers!
11430
+ // Non-destructive Source Control Diff: side-by-side Monaco DiffEditor when available, with unified fallback!
10494
11431
  if (this._activeScmDiffFile && inlineDiffHost) {
10495
11432
  if (monacoHost) monacoHost.style.display = 'none';
10496
11433
  if (sqlHost) sqlHost.style.display = 'none';
@@ -10505,6 +11442,9 @@ int main() {
10505
11442
  this._updateStatusBar();
10506
11443
  return;
10507
11444
  }
11445
+ if (this._scmDiffManager && typeof this._scmDiffManager.closeInlineDiff === 'function') {
11446
+ try { this._scmDiffManager.closeInlineDiff(); } catch (_err) { void _err; }
11447
+ }
10508
11448
  if (inlineDiffHost) {
10509
11449
  inlineDiffHost.hidden = true;
10510
11450
  if (inlineDiffHost.style) inlineDiffHost.style.display = 'none';
@@ -10572,7 +11512,7 @@ int main() {
10572
11512
  sqlHost &&
10573
11513
  sqlPack &&
10574
11514
  typeof sqlPack.createSqlEditor === 'function' &&
10575
- (!this.editor || (this.options && this.options.editorEngine !== 'monaco'))
11515
+ (this._isSingleFileSqlMode() || !this.editor || (this.options && this.options.editorEngine === 'sql'))
10576
11516
  );
10577
11517
 
10578
11518
  if (isMd && this._mdPreviewOpen) {
@@ -10655,6 +11595,7 @@ int main() {
10655
11595
  if (model && this.editor.getModel() !== model) {
10656
11596
  this.editor.setModel(model);
10657
11597
  }
11598
+ this._updateEditorGitGutter();
10658
11599
  const pos = typeof this.editor.getPosition === 'function' ? this.editor.getPosition() : null;
10659
11600
  if (pos) {
10660
11601
  this.cursorPos = {
@@ -10834,6 +11775,11 @@ int main() {
10834
11775
  const keyLower = (e.key || '').toLowerCase();
10835
11776
  const mod = Boolean(e.metaKey || e.ctrlKey);
10836
11777
  const tgt = e.target;
11778
+ const inTerminal = Boolean(
11779
+ tgt &&
11780
+ typeof tgt.closest === 'function' &&
11781
+ tgt.closest('#cl-terminal-surface, .xterm, .codelab-terminal-pane')
11782
+ );
10837
11783
  const inCustomContentEditable = Boolean(
10838
11784
  tgt &&
10839
11785
  (tgt.isContentEditable || (typeof tgt.closest === 'function' && tgt.closest('[contenteditable="true"]'))) &&
@@ -10842,6 +11788,15 @@ int main() {
10842
11788
  if (inCustomContentEditable && mod && !e.shiftKey && !e.altKey && keyLower === 'b') {
10843
11789
  return;
10844
11790
  }
11791
+ if (inTerminal && e.ctrlKey && !e.metaKey && !e.shiftKey && !e.altKey && keyLower === 'b') {
11792
+ return;
11793
+ }
11794
+ if (inTerminal && mod && !e.shiftKey && !e.altKey && e.key === '\\') {
11795
+ e.preventDefault();
11796
+ e.stopPropagation();
11797
+ this.splitActiveTerminalSession();
11798
+ return;
11799
+ }
10845
11800
  if (mod && !e.shiftKey && !e.altKey && keyLower === 's') {
10846
11801
  e.preventDefault();
10847
11802
  e.stopPropagation();
@@ -10873,8 +11828,13 @@ int main() {
10873
11828
  this.setPanelVisible(true, { skipRender: true });
10874
11829
  this.createTerminalSession();
10875
11830
  this.switchDrawerTab('terminal', { ensureVisible: true });
10876
- const termInp = this.container ? this.container.querySelector('#cl-repl-input') : null;
10877
- if (termInp && typeof termInp.focus === 'function') termInp.focus();
11831
+ const activeXt = this._getActiveXtermEngine();
11832
+ if (activeXt && typeof activeXt.focus === 'function') {
11833
+ activeXt.focus();
11834
+ } else {
11835
+ const termInp = this.container ? this.container.querySelector('#cl-repl-input') : null;
11836
+ if (termInp && typeof termInp.focus === 'function') termInp.focus();
11837
+ }
10878
11838
  } else {
10879
11839
  this.toggleTerminal();
10880
11840
  }
@@ -11932,11 +12892,23 @@ int main() {
11932
12892
  this.closeSettings();
11933
12893
  return;
11934
12894
  }
12895
+ if (tabKey === '__welcome__') {
12896
+ this.closeWelcomeTab();
12897
+ return;
12898
+ }
11935
12899
  const fname = closeBtn.dataset.clCloseFile || closeBtn.dataset.clFile || tabEl.dataset.clFile;
11936
12900
  if (fname) this.closeTab(fname);
11937
12901
  return;
11938
12902
  }
11939
12903
 
12904
+ const welcomeTabBtn = e.target.closest('[data-cl-tab="__welcome__"]');
12905
+ if (welcomeTabBtn) {
12906
+ this._activeScmDiffFile = null;
12907
+ this.activeTab = '__welcome__';
12908
+ this._syncActiveFileToView();
12909
+ return;
12910
+ }
12911
+
11940
12912
  const settingsTabBtn = e.target.closest('[data-cl-tab="__settings__"]');
11941
12913
  if (settingsTabBtn) {
11942
12914
  this._activeScmDiffFile = null;
@@ -12281,6 +13253,8 @@ int main() {
12281
13253
  } else if (action === 'new-terminal-session') {
12282
13254
  this.createTerminalSession();
12283
13255
  if (this.drawerTab !== 'terminal') this.switchDrawerTab('terminal');
13256
+ } else if (action === 'split-terminal-session') {
13257
+ this.splitActiveTerminalSession();
12284
13258
  } else if (action === 'kill-terminal-session') {
12285
13259
  this.killActiveTerminalSession();
12286
13260
  } else if (action === 'switch-terminal-session') {
@@ -12290,6 +13264,49 @@ int main() {
12290
13264
  e.stopPropagation();
12291
13265
  const sid = actionBtn.dataset.sessionId;
12292
13266
  if (sid) this.closeTerminalSession(sid);
13267
+ } else if (action === 'reveal-symbol') {
13268
+ const symFile = actionBtn.dataset.symbolFile || this.activeFile;
13269
+ const symLine = Math.max(1, Number(actionBtn.dataset.symbolLine || 1));
13270
+ const symCol = Math.max(1, Number(actionBtn.dataset.symbolCol || 1));
13271
+ if (symFile) {
13272
+ this.openFile(symFile);
13273
+ this._revealLineColInActiveEditor(symLine, symCol);
13274
+ }
13275
+ } else if (action === 'open-welcome') {
13276
+ this.openWelcomeTab();
13277
+ } else if (action === 'welcome-new-file') {
13278
+ this.closeWelcomeTab();
13279
+ this.setSidebarView('explorer', { ensureOpen: true, focus: false });
13280
+ this.startInlineCreate('file', this.explorerFolder || '');
13281
+ } else if (action === 'welcome-clone-repo') {
13282
+ this.openCloneDialog();
13283
+ } else if (action === 'welcome-open-recent') {
13284
+ const wid = actionBtn.dataset.workspaceId;
13285
+ if (wid) {
13286
+ this.closeWelcomeTab();
13287
+ this.switchWorkspace(wid);
13288
+ }
13289
+ } else if (action === 'welcome-load-template') {
13290
+ const demoId = actionBtn.dataset.demo || '';
13291
+ if (this.options && typeof this.options.onSelectWelcomeTemplate === 'function') {
13292
+ this.closeWelcomeTab();
13293
+ this.options.onSelectWelcomeTemplate(demoId, this);
13294
+ } else if (this.options && Array.isArray(this.options.welcomeTemplates)) {
13295
+ const tpl = this.options.welcomeTemplates.find((t) => t && t.id === demoId);
13296
+ if (tpl && tpl.files && typeof tpl.files === 'object') {
13297
+ this.closeWelcomeTab();
13298
+ if (tpl.language) this.lang = tpl.language;
13299
+ if (tpl.entry) this.entry = tpl.entry;
13300
+ if (tpl.title) this.title = tpl.title;
13301
+ this.setFiles(tpl.files);
13302
+ this._updateTopbarBrandTitle();
13303
+ const firstFile = tpl.entry && tpl.files[tpl.entry] ? tpl.entry : Object.keys(tpl.files)[0];
13304
+ if (firstFile) this.openFile(firstFile);
13305
+ }
13306
+ }
13307
+ } else if (action === 'scm-toggle-diff-mode') {
13308
+ this._scmForceUnifiedDiff = !this._scmForceUnifiedDiff;
13309
+ this._syncActiveFileToView();
12293
13310
  } else if (action === 'scm-init') {
12294
13311
  this._initGitRepoInScm();
12295
13312
  } else if (action === 'scm-stage-file' || action === 'scm-stage') {
@@ -12849,6 +13866,15 @@ int main() {
12849
13866
  return builtin;
12850
13867
  }
12851
13868
 
13869
+ toggleCommandPalette(open, mode = 'commands') {
13870
+ const isOpen = Boolean(this.container && this.container.querySelector('#cl-modal-slot .codelab-palette'));
13871
+ if (open === false || (open === undefined && isOpen)) {
13872
+ this.closeCommandPalette();
13873
+ } else {
13874
+ this.openCommandPalette(mode);
13875
+ }
13876
+ }
13877
+
12852
13878
  openCommandPalette(mode = 'commands') {
12853
13879
  const slot = this.container.querySelector('#cl-modal-slot');
12854
13880
  if (!slot) return;
@@ -12918,20 +13944,104 @@ int main() {
12918
13944
  if (!listEl) return;
12919
13945
  const trimmed = String(rawValue || '').trim();
12920
13946
  const isCommandQuery = trimmed.startsWith('>') || (this.paletteMode === 'commands' && rawValue.startsWith('>'));
12921
- const query = (trimmed.startsWith('>') ? trimmed.slice(1) : trimmed).trim().toLowerCase();
13947
+ const isDocSymbolQuery = !isCommandQuery && trimmed.startsWith('@');
13948
+ const isWsSymbolQuery = !isCommandQuery && trimmed.startsWith('#');
13949
+ const rawQuery = isCommandQuery
13950
+ ? trimmed.replace(/^>\s*/, '')
13951
+ : (isDocSymbolQuery || isWsSymbolQuery ? trimmed.slice(1).trim() : trimmed);
13952
+ const query = rawQuery.toLowerCase();
13953
+ const fuzzyScore = (_wbComponents && (typeof _wbComponents.fuzzyScoreText === 'function' || typeof _wbComponents.scoreFuzzyMatch === 'function'))
13954
+ ? (_wbComponents.fuzzyScoreText || _wbComponents.scoreFuzzyMatch)
13955
+ : null;
13956
+ const fuzzyHl = (_wbComponents && (typeof _wbComponents.renderHighlightedText === 'function' || typeof _wbComponents.highlightFuzzyMatches === 'function'))
13957
+ ? (_wbComponents.renderHighlightedText || _wbComponents.highlightFuzzyMatches)
13958
+ : null;
12922
13959
 
12923
13960
  let items = [];
12924
13961
  if (isCommandQuery) {
12925
13962
  const cmds = this._getPaletteCommands();
12926
- items = cmds
12927
- .filter(c => !query || c.label.toLowerCase().includes(query) || c.id.toLowerCase().includes(query))
12928
- .map(c => ({
13963
+ if (query && fuzzyScore) {
13964
+ const scored = [];
13965
+ for (const c of cmds) {
13966
+ const mLabel = fuzzyScore(rawQuery, c.label);
13967
+ const mId = fuzzyScore(rawQuery, c.id);
13968
+ const best = mLabel || mId;
13969
+ if (best) {
13970
+ scored.push({
13971
+ score: (mLabel ? mLabel.score : 0) || (mId ? mId.score - 4 : 0),
13972
+ indices: mLabel ? mLabel.indices : [],
13973
+ cmd: c
13974
+ });
13975
+ }
13976
+ }
13977
+ scored.sort((a, b) => b.score - a.score);
13978
+ items = scored.map(({ cmd: c, indices }) => ({
12929
13979
  type: 'command',
12930
13980
  id: c.id,
12931
13981
  label: c.label,
13982
+ labelHtml: fuzzyHl && indices.length > 0 ? fuzzyHl(c.label, indices) : escapeHtml(c.label),
12932
13983
  shortcut: c.shortcut || '',
12933
13984
  action: c.action
12934
13985
  }));
13986
+ } else {
13987
+ items = cmds
13988
+ .filter(c => !query || c.label.toLowerCase().includes(query) || c.id.toLowerCase().includes(query))
13989
+ .map(c => ({
13990
+ type: 'command',
13991
+ id: c.id,
13992
+ label: c.label,
13993
+ labelHtml: escapeHtml(c.label),
13994
+ shortcut: c.shortcut || '',
13995
+ action: c.action
13996
+ }));
13997
+ }
13998
+ } else if (isDocSymbolQuery) {
13999
+ const activeTarget = (this.activeFile && this.activeTab !== '__settings__' && this.activeTab !== '__welcome__')
14000
+ ? this.activeFile
14001
+ : this._pickDefaultFile();
14002
+ const symbols = (activeTarget && _wbComponents && typeof _wbComponents.extractDocumentSymbols === 'function')
14003
+ ? _wbComponents.extractDocumentSymbols(activeTarget, String(this.files[activeTarget] ?? ''))
14004
+ : [];
14005
+ items = symbols
14006
+ .filter(sym => !query || sym.name.toLowerCase().includes(query))
14007
+ .map(sym => ({
14008
+ type: 'symbol',
14009
+ id: `${activeTarget}:${sym.line}:${sym.name}`,
14010
+ label: `${sym.name} (${sym.kind})`,
14011
+ labelHtml: `${escapeHtml(sym.name)} <span class="cl-ui-palette-sub">${escapeHtml(sym.kind)} · Ln ${sym.line}</span>`,
14012
+ shortcut: activeTarget || '',
14013
+ action: () => {
14014
+ if (activeTarget) {
14015
+ this.openFile(activeTarget);
14016
+ this._revealLineColInActiveEditor(sym.line || 1, sym.column || 1);
14017
+ }
14018
+ }
14019
+ }));
14020
+ } else if (isWsSymbolQuery) {
14021
+ const allSymbols = [];
14022
+ if (_wbComponents && typeof _wbComponents.extractDocumentSymbols === 'function') {
14023
+ for (const fname of this._orderedFileNames()) {
14024
+ if (this._isPathExcluded(fname)) continue;
14025
+ const syms = _wbComponents.extractDocumentSymbols(fname, String(this.files[fname] ?? ''));
14026
+ for (const sym of syms) {
14027
+ allSymbols.push({ file: fname, sym });
14028
+ }
14029
+ }
14030
+ }
14031
+ items = allSymbols
14032
+ .filter(({ sym, file }) => !query || sym.name.toLowerCase().includes(query) || file.toLowerCase().includes(query))
14033
+ .slice(0, 80)
14034
+ .map(({ sym, file }) => ({
14035
+ type: 'symbol',
14036
+ id: `${file}:${sym.line}:${sym.name}`,
14037
+ label: `${sym.name} — ${file}`,
14038
+ labelHtml: `${escapeHtml(sym.name)} <span class="cl-ui-palette-sub">${escapeHtml(file)}:${sym.line}</span>`,
14039
+ shortcut: sym.kind,
14040
+ action: () => {
14041
+ this.openFile(file);
14042
+ this._revealLineColInActiveEditor(sym.line || 1, sym.column || 1);
14043
+ }
14044
+ }));
12935
14045
  } else {
12936
14046
  const files = this._orderedFileNames().filter(f => !this._isPathExcluded(f));
12937
14047
  const mod = getModular();
@@ -12940,17 +14050,35 @@ int main() {
12940
14050
  ...(Array.isArray(searchExcl) ? searchExcl : []),
12941
14051
  ...this._getExcludePatterns()
12942
14052
  ];
12943
- const ranked = (mod && typeof mod.rankWorkspaceFiles === 'function')
12944
- ? mod.rankWorkspaceFiles(files, query, excludePatterns)
12945
- : files.filter(f => !query || f.toLowerCase().includes(query));
12946
- items = ranked
12947
- .map(f => ({
14053
+ if (query && fuzzyScore) {
14054
+ const scored = [];
14055
+ for (const f of files) {
14056
+ const m = fuzzyScore(rawQuery, f);
14057
+ if (m) scored.push({ file: f, score: m.score + (f === this.activeFile ? 3 : 0), indices: m.indices });
14058
+ }
14059
+ scored.sort((a, b) => b.score - a.score);
14060
+ items = scored.map(({ file: f, indices }) => ({
12948
14061
  type: 'file',
12949
14062
  id: f,
12950
14063
  label: f,
14064
+ labelHtml: fuzzyHl && indices.length > 0 ? fuzzyHl(f, indices) : escapeHtml(f),
12951
14065
  shortcut: f === this.activeFile ? 'Active' : '',
12952
14066
  action: () => this.openFile(f)
12953
14067
  }));
14068
+ } else {
14069
+ const ranked = (mod && typeof mod.rankWorkspaceFiles === 'function')
14070
+ ? mod.rankWorkspaceFiles(files, query, excludePatterns)
14071
+ : files.filter(f => !query || f.toLowerCase().includes(query));
14072
+ items = ranked
14073
+ .map(f => ({
14074
+ type: 'file',
14075
+ id: f,
14076
+ label: f,
14077
+ labelHtml: escapeHtml(f),
14078
+ shortcut: f === this.activeFile ? 'Active' : '',
14079
+ action: () => this.openFile(f)
14080
+ }));
14081
+ }
12954
14082
  }
12955
14083
 
12956
14084
  this._currentPaletteItems = items;
@@ -12959,13 +14087,14 @@ int main() {
12959
14087
  }
12960
14088
 
12961
14089
  if (items.length === 0) {
12962
- listEl.innerHTML = `<div class="codelab-palette__empty">No matching ${isCommandQuery ? 'commands' : 'files'} found</div>`;
14090
+ const kindLabel = isCommandQuery ? 'commands' : (isDocSymbolQuery || isWsSymbolQuery ? 'symbols' : 'files');
14091
+ listEl.innerHTML = `<div class="codelab-palette__empty">No matching ${kindLabel} found</div>`;
12963
14092
  return;
12964
14093
  }
12965
14094
 
12966
14095
  listEl.innerHTML = items.map((item, idx) => `
12967
14096
  <button type="button" class="codelab-palette__item ${idx === this.paletteSelectedIndex ? 'is-selected' : ''}" role="option" aria-selected="${idx === this.paletteSelectedIndex}" data-palette-idx="${idx}" data-palette-id="${escapeHtml(item.id)}">
12968
- <span class="codelab-palette__item-label">${escapeHtml(item.label)}</span>
14097
+ <span class="codelab-palette__item-label">${item.labelHtml || escapeHtml(item.label)}</span>
12969
14098
  ${item.shortcut ? `<span class="codelab-palette__item-kbd">${escapeHtml(item.shortcut)}</span>` : ''}
12970
14099
  </button>
12971
14100
  `).join('');
@@ -13306,12 +14435,25 @@ int main() {
13306
14435
  const mainEl = this.container.querySelector('.codelab-workbench-main, .codelab-main');
13307
14436
  if (!mainEl) return;
13308
14437
  const rect = mainEl.getBoundingClientRect();
13309
- const minH = 110;
13310
- const maxH = Math.max(minH, Math.floor(rect.height * 0.75));
13311
- const nextH = Math.min(maxH, Math.max(minH, Math.round(rect.bottom - ev.clientY)));
14438
+ const rawH = Math.round(rect.bottom - ev.clientY);
14439
+ if (rawH < 56) {
14440
+ if (this.panelVisible) {
14441
+ this._savedPanelHeight = Math.max(140, this.panelHeight || 220);
14442
+ this.setPanelVisible(false, { skipRender: true, skipSave: true });
14443
+ }
14444
+ return;
14445
+ }
14446
+ if (!this.panelVisible && rawH >= 72) {
14447
+ this.setPanelVisible(true, { skipRender: true, skipSave: true });
14448
+ }
14449
+ const minH = 96;
14450
+ const maxH = Math.max(minH, Math.floor(rect.height * 0.82));
14451
+ const nextH = Math.min(maxH, Math.max(minH, rawH));
13312
14452
  this.panelHeight = nextH;
13313
14453
  this._setShellCssVar(curShell, '--cl-drawer-height', `${nextH}px`);
13314
- if (this.editor) this.editor.layout();
14454
+ if (this.editor && typeof this.editor.layout === 'function') this.editor.layout();
14455
+ const xt = this._getActiveXtermEngine();
14456
+ if (xt && typeof xt.fit === 'function') xt.fit();
13315
14457
  },
13316
14458
  onEnd: () => {
13317
14459
  this._saveState();
@@ -13327,6 +14469,7 @@ int main() {
13327
14469
  if (fSplitter && !fSplitter._clDblBound) {
13328
14470
  fSplitter._clDblBound = true;
13329
14471
  fSplitter.addEventListener('dblclick', () => {
14472
+ if (!this.sidebarVisible) this.setSidebarVisible(true);
13330
14473
  applyExplorerWidth(260, this.container.querySelector('.codelab'));
13331
14474
  this._saveState();
13332
14475
  });
@@ -13337,11 +14480,20 @@ int main() {
13337
14480
  const bodyEl = this.container.querySelector('.codelab-body');
13338
14481
  const sidebarEl = this.container.querySelector('#cl-sidebar, .codelab-sidebar');
13339
14482
  const bodyRect = (bodyEl || curShell).getBoundingClientRect();
13340
- const sbRect = sidebarEl ? sidebarEl.getBoundingClientRect() : bodyRect;
14483
+ const sbRect = sidebarEl && this.sidebarVisible ? sidebarEl.getBoundingClientRect() : bodyRect;
14484
+ const isRight = curShell.classList.contains('sidebar-right');
14485
+ const rawW = isRight ? (bodyRect.right - 48 - ev.clientX) : (ev.clientX - (this.sidebarVisible ? sbRect.left : bodyRect.left + 48));
14486
+ if (rawW < 72) {
14487
+ if (this.sidebarVisible) {
14488
+ this.setSidebarVisible(false);
14489
+ }
14490
+ return;
14491
+ }
14492
+ if (!this.sidebarVisible && rawW >= 96) {
14493
+ this.setSidebarVisible(true);
14494
+ }
13341
14495
  const minW = 150;
13342
14496
  const maxW = Math.max(minW, Math.floor(bodyRect.width * 0.5));
13343
- const isRight = curShell.classList.contains('sidebar-right');
13344
- const rawW = isRight ? (sbRect.right - ev.clientX) : (ev.clientX - sbRect.left);
13345
14497
  const nextW = Math.min(maxW, Math.max(minW, Math.round(rawW)));
13346
14498
  applyExplorerWidth(nextW, curShell);
13347
14499
  },
@@ -13919,37 +15071,37 @@ int main() {
13919
15071
  <button type="button" class="codelab-btn" data-cl-action="close-modal">Close (Esc)</button>
13920
15072
  </div>
13921
15073
  </div>
13922
- <div class="codelab-modal__body" style="font-family:var(--cl-font-sans);">
13923
- <div style="display:flex;gap:8px;margin-bottom:16px;">
13924
- <input id="cl-pkg-input" type="text" placeholder="Add npm package (e.g. zod, lru-cache, nanoid@5.0.0)..." style="flex:1;height:32px;padding:0 10px;background:var(--cl-bg);border:1px solid var(--cl-border-strong);border-radius:var(--cl-radius-sm);color:var(--cl-fg);font-family:var(--cl-font-mono);font-size:12px;outline:none;" />
15074
+ <div class="codelab-modal__body">
15075
+ <div class="cl-ui-form-row">
15076
+ <input id="cl-pkg-input" class="cl-ui-input cl-ui-input--mono" type="text" placeholder="Add npm package (e.g. zod, lru-cache, nanoid@5.0.0)..." />
13925
15077
  <button type="button" class="codelab-btn codelab-btn--primary" data-cl-action="add-package">+ Add Dependency</button>
13926
15078
  </div>
13927
15079
  <div style="margin-bottom:16px;">
13928
- <div style="font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:0.06em;color:var(--cl-fg-muted);margin-bottom:8px;">
15080
+ <div class="cl-ui-section-label">
13929
15081
  External NPM Packages (${pkgs.length})
13930
15082
  </div>
13931
15083
  ${pkgs.length === 0 ? `
13932
- <div style="padding:12px;border:1px solid var(--cl-border);border-radius:var(--cl-radius-sm);background:var(--cl-bg);color:var(--cl-fg-muted);font-size:12.5px;">
15084
+ <div class="cl-ui-card-note">
13933
15085
  No external npm packages imported yet. Any <code>import ... from 'pkg'</code> or <code>require('pkg')</code> in your code is automatically resolved via <strong>jsDelivr</strong> when you run or test.
13934
15086
  </div>
13935
15087
  ` : `
13936
- <div style="display:flex;flex-direction:column;gap:6px;">
15088
+ <div class="cl-ui-stack-xs">
13937
15089
  ${pkgs.map(p => `
13938
- <div style="display:flex;align-items:center;justify-content:space-between;padding:8px 12px;border:1px solid var(--cl-border);border-radius:var(--cl-radius-sm);background:var(--cl-bg);font-family:var(--cl-font-mono);font-size:12px;">
13939
- <span style="color:var(--cl-fg);font-weight:600;">${escapeHtml(p.name)}</span>
13940
- <span style="color:var(--cl-accent);">${escapeHtml(p.version)} · jsDelivr</span>
15090
+ <div class="cl-ui-pkg-row">
15091
+ <span class="cl-ui-pkg-row__name">${escapeHtml(p.name)}</span>
15092
+ <span class="cl-ui-pkg-row__meta">${escapeHtml(p.version)} · jsDelivr</span>
13941
15093
  </div>
13942
15094
  `).join('')}
13943
15095
  </div>
13944
15096
  `}
13945
15097
  </div>
13946
15098
  <div>
13947
- <div style="font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:0.06em;color:var(--cl-fg-muted);margin-bottom:8px;">
15099
+ <div class="cl-ui-section-label">
13948
15100
  Built-in Virtual Node.js Modules (Zero-Latency In-Memory VFS)
13949
15101
  </div>
13950
- <div style="display:flex;flex-wrap:wrap;gap:6px;">
15102
+ <div class="cl-ui-chip-wrap">
13951
15103
  ${builtins.map(b => `
13952
- <span style="padding:3px 8px;border:1px solid var(--cl-border);border-radius:4px;background:var(--cl-bg);font-family:var(--cl-font-mono);font-size:11px;color:var(--cl-fg-muted);">${b}</span>
15104
+ <span class="cl-ui-chip">${b}</span>
13953
15105
  `).join('')}
13954
15106
  </div>
13955
15107
  </div>
@@ -14032,6 +15184,43 @@ int main() {
14032
15184
  `;
14033
15185
  }
14034
15186
 
15187
+ _openModalDialog(slot) {
15188
+ if (!slot || typeof slot.querySelector !== 'function') return null;
15189
+ const dlg = slot.querySelector('dialog.codelab-dialog');
15190
+ if (!dlg) return null;
15191
+ if (typeof dlg.showModal === 'function') {
15192
+ try {
15193
+ if (!dlg.open) dlg.showModal();
15194
+ } catch (err) {
15195
+ void err;
15196
+ dlg.setAttribute('open', '');
15197
+ }
15198
+ } else {
15199
+ dlg.setAttribute('open', '');
15200
+ }
15201
+ dlg.addEventListener('cancel', (ev) => {
15202
+ ev.preventDefault();
15203
+ this.closeModal();
15204
+ });
15205
+ if (typeof HTMLDialogElement === 'undefined' || !('closedBy' in HTMLDialogElement.prototype)) {
15206
+ dlg.addEventListener('click', (ev) => {
15207
+ if (!ev || typeof dlg.getBoundingClientRect !== 'function') return;
15208
+ const rect = dlg.getBoundingClientRect();
15209
+ if (rect.width <= 0 || rect.height <= 0) return;
15210
+ const clickedInDialog = (
15211
+ rect.top <= ev.clientY &&
15212
+ ev.clientY <= rect.top + rect.height &&
15213
+ rect.left <= ev.clientX &&
15214
+ ev.clientX <= rect.left + rect.width
15215
+ );
15216
+ if (!clickedInDialog) {
15217
+ this.closeModal();
15218
+ }
15219
+ });
15220
+ }
15221
+ return dlg;
15222
+ }
15223
+
14035
15224
  closeModal(opts = {}) {
14036
15225
  this._lastBackdropPointerDownTarget = null;
14037
15226
  const slot = this.container ? this.container.querySelector('#cl-modal-slot') : null;
@@ -14040,7 +15229,13 @@ int main() {
14040
15229
  this._modalReturnFocusEl = null;
14041
15230
  const onCloseCb = this._onModalClosedCallback || null;
14042
15231
  this._onModalClosedCallback = null;
14043
- if (slot) slot.innerHTML = '';
15232
+ if (slot) {
15233
+ const openDlg = typeof slot.querySelector === 'function' ? slot.querySelector('dialog.codelab-dialog[open]') : null;
15234
+ if (openDlg && typeof openDlg.close === 'function') {
15235
+ try { openDlg.close(); } catch (_err) { void _err; }
15236
+ }
15237
+ slot.innerHTML = '';
15238
+ }
14044
15239
  if (typeof onCloseCb === 'function') {
14045
15240
  try { onCloseCb(); } catch (_err) { void _err; }
14046
15241
  }
@@ -14078,6 +15273,7 @@ int main() {
14078
15273
  const configuredTimeoutMs = this.configuration
14079
15274
  ? Math.max(500, Math.min(120000, Number(this.configuration.get('runtime.timeoutMs', 8000)) || 8000))
14080
15275
  : 8000;
15276
+ const activeSignal = execOptions.signal || this._activeCommandAbortController?.signal;
14081
15277
  const payload = {
14082
15278
  ...execOptions,
14083
15279
  timeoutMs: execOptions && execOptions.timeoutMs !== undefined ? execOptions.timeoutMs : configuredTimeoutMs,
@@ -14086,7 +15282,8 @@ int main() {
14086
15282
  cppCompiler: execOptions.cppCompiler || this.cppCompiler,
14087
15283
  onStdout: execOptions.onStdout || ((chunk) => this._appendTerminalStream('stdout', chunk)),
14088
15284
  onStderr: execOptions.onStderr || ((chunk) => this._appendTerminalStream('stderr', chunk)),
14089
- signal: execOptions.signal || this._activeCommandAbortController?.signal
15285
+ onRequestStdin: execOptions.onRequestStdin || ((promptText) => this._requestInteractiveTerminalStdin(promptText, activeSignal)),
15286
+ signal: activeSignal
14090
15287
  };
14091
15288
  try {
14092
15289
  const isCppEntry = Boolean(payload && typeof payload.entry === 'string' && /\.(cpp|cc|cxx|wasm)$/i.test(payload.entry));
@@ -16023,6 +17220,13 @@ int main() {
16023
17220
  if (outSurface && outSurface.style) {
16024
17221
  outSurface.style.fontSize = `${termFontSize}px`;
16025
17222
  }
17223
+ if (this._xtermEngines instanceof Map) {
17224
+ const maxSbCfg = this._getTerminalScrollback();
17225
+ for (const eng of this._xtermEngines.values()) {
17226
+ if (eng && typeof eng.setFontSize === 'function') eng.setFontSize(termFontSize);
17227
+ if (eng && typeof eng.setMaxScrollback === 'function') eng.setMaxScrollback(maxSbCfg);
17228
+ }
17229
+ }
16026
17230
  const trimmedLogs = this._trimTerminalLogs();
16027
17231
  if (trimmedLogs && (this.drawerTab === 'terminal' || this.drawerTab === 'output')) {
16028
17232
  this._renderDrawerBody();
@@ -16297,7 +17501,7 @@ int main() {
16297
17501
  return abs.replace(/^\/+/, '');
16298
17502
  }
16299
17503
 
16300
- async _handleReplCommand(cmd) {
17504
+ async _handleReplCommand(cmd, opts = null) {
16301
17505
  if (this.isRunning) return;
16302
17506
  const trimmed = (cmd || '').trim();
16303
17507
  if (!trimmed) return;
@@ -16305,21 +17509,24 @@ int main() {
16305
17509
  this.replHistory.push(trimmed);
16306
17510
  }
16307
17511
  this.replHistoryIdx = -1;
16308
- const cwdShort = (this.cwd || '/workspace').replace(/^\/workspace\/?/, '') || '~';
16309
- const promptPrefix = this.inRepl ? '> ' : `codelab:${cwdShort}$ `;
16310
- const echoLine = `${promptPrefix}${trimmed}`;
16311
- this._pushTerminalLog({ type: 'system', text: echoLine });
16312
- const maxSbEcho = this._getTerminalScrollback();
16313
- if (this.terminalLogs.length > maxSbEcho) {
16314
- this.terminalLogs.splice(0, this.terminalLogs.length - maxSbEcho);
16315
- }
16316
- const termLogEl = this.container ? this.container.querySelector('#cl-terminal-log') : null;
16317
- const ptyOwnsDom = Boolean(this.ptyEngine && this.ptyEngine.container);
16318
- if (termLogEl && typeof document !== 'undefined' && !ptyOwnsDom) {
16319
- const echoEl = document.createElement('div');
16320
- echoEl.className = 'codelab-log-line system';
16321
- echoEl.innerHTML = ansiToHtml ? ansiToHtml(echoLine) : escapeHtml(echoLine);
16322
- termLogEl.appendChild(echoEl);
17512
+ const skipEcho = Boolean(opts && opts.skipEcho);
17513
+ if (!skipEcho) {
17514
+ const cwdShort = (this.cwd || '/workspace').replace(/^\/workspace\/?/, '') || '~';
17515
+ const promptPrefix = this.inRepl ? '> ' : `codelab:${cwdShort}$ `;
17516
+ const echoLine = `${promptPrefix}${trimmed}`;
17517
+ this._pushTerminalLog({ type: 'system', text: echoLine });
17518
+ const maxSbEcho = this._getTerminalScrollback();
17519
+ if (this.terminalLogs.length > maxSbEcho) {
17520
+ this.terminalLogs.splice(0, this.terminalLogs.length - maxSbEcho);
17521
+ }
17522
+ const termLogEl = this.container ? this.container.querySelector('#cl-terminal-log') : null;
17523
+ const ptyOwnsDom = Boolean((this.ptyEngine && this.ptyEngine.container) || this._getActiveXtermEngine());
17524
+ if (termLogEl && typeof document !== 'undefined' && !ptyOwnsDom) {
17525
+ const echoEl = document.createElement('div');
17526
+ echoEl.className = 'codelab-log-line system';
17527
+ echoEl.innerHTML = ansiToHtml ? ansiToHtml(echoLine) : escapeHtml(echoLine);
17528
+ termLogEl.appendChild(echoEl);
17529
+ }
16323
17530
  }
16324
17531
 
16325
17532
  if (this.inRepl) {
@@ -16353,6 +17560,7 @@ int main() {
16353
17560
  files: { ...this.files },
16354
17561
  mode: 'repl',
16355
17562
  replCode: trimmed,
17563
+ replSessionId: this._activeTerminalSessionId || 'default',
16356
17564
  signal: abortCtrl.signal,
16357
17565
  onStdout: (c) => { streamedStdout = true; this._appendTerminalStream('stdout', c); },
16358
17566
  onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
@@ -16393,21 +17601,27 @@ int main() {
16393
17601
  this._renderDrawerBody();
16394
17602
  return;
16395
17603
  }
16396
- if (trimmed === 'run' || trimmed === 'npm start' || trimmed === 'npm run demo') {
17604
+ const hasPkgJson = Boolean(this.files && this.files['package.json']);
17605
+ if (trimmed === 'run' || ((this.hasGuidedLab || !hasPkgJson) && (trimmed === 'npm start' || trimmed === 'npm run demo'))) {
16397
17606
  await this.runDemo();
16398
17607
  return;
16399
17608
  }
16400
- if (trimmed === 'test' || trimmed === 'npm test' || trimmed === 'npm t') {
17609
+ if (trimmed === 'test' || ((this.hasGuidedLab || !hasPkgJson) && (trimmed === 'npm test' || trimmed === 'npm t'))) {
16401
17610
  await this.runTests();
16402
17611
  return;
16403
17612
  }
16404
17613
 
16405
17614
  const firstWord = (trimmed.split(/\s+/)[0] || '').replace(/^.*\//, '');
17615
+ const isEnvVarAssignment = /^[A-Za-z_][A-Za-z0-9_]*=/.test(trimmed);
16406
17616
  const shellKnowsCommand = Boolean(
16407
- firstWord &&
17617
+ isEnvVarAssignment ||
17618
+ trimmed.startsWith('./') ||
17619
+ trimmed.startsWith('../') ||
17620
+ trimmed.startsWith('/') ||
17621
+ (firstWord &&
16408
17622
  this.shell &&
16409
17623
  typeof this.shell.hasCommand === 'function' &&
16410
- this.shell.hasCommand(firstWord)
17624
+ this.shell.hasCommand(firstWord))
16411
17625
  );
16412
17626
  const looksLikeJsExpr = !shellKnowsCommand && (
16413
17627
  /^(const|let|var|function|class|await|return|typeof|instanceof|new\s+|Math\.|JSON\.|Object\.|Array\.|Promise\.|console\.|process\.|Buffer\.|require\s*\(|import\s*\(|[0-9]+\s*[\+\-\*\/\%]|['"`\[{])/.test(trimmed)
@@ -16421,7 +17635,6 @@ int main() {
16421
17635
  this._updateRunStateUI();
16422
17636
  let streamedStdout = false;
16423
17637
  let streamedStderr = false;
16424
- const logsCountBefore = this.terminalLogs.length;
16425
17638
 
16426
17639
  try {
16427
17640
  this._syncFilesToShellVfs();
@@ -16435,6 +17648,7 @@ int main() {
16435
17648
  streamedStderr = true;
16436
17649
  this._appendTerminalStream('stderr', c);
16437
17650
  },
17651
+ onRequestStdin: (promptText) => this._requestInteractiveTerminalStdin(promptText, abortCtrl.signal),
16438
17652
  signal: abortCtrl.signal
16439
17653
  });
16440
17654
  this._flushTerminalStream();
@@ -16443,6 +17657,8 @@ int main() {
16443
17657
  this._syncVfsSnapshot(null, true);
16444
17658
  if (/^\s*git\b/.test(trimmed) || (this.shell && this.shell.gitState && this.shell.gitState.initialized)) {
16445
17659
  this._saveState();
17660
+ this._updateEditorGitGutter();
17661
+ this._renderFileLists();
16446
17662
  }
16447
17663
  if (this.activeSidebarView === 'scm' && typeof this._renderScmSidebar === 'function') {
16448
17664
  this._renderScmSidebar();
@@ -17009,22 +18225,23 @@ int main() {
17009
18225
  : `Are you sure you want to discard all working-tree changes in "${cleanRel}" and restore HEAD?`;
17010
18226
 
17011
18227
  slot.innerHTML = `
17012
- <div class="codelab-modal-backdrop">
17013
- <div class="codelab-modal" role="dialog" aria-modal="true" aria-labelledby="cl-discard-modal-title" aria-describedby="cl-discard-modal-desc" style="max-width:420px;">
18228
+ <dialog class="codelab-dialog" closedby="any" aria-labelledby="cl-discard-modal-title" aria-describedby="cl-discard-modal-desc" style="max-width:420px;">
18229
+ <div class="codelab-modal" role="document">
17014
18230
  <div class="codelab-modal__header">
17015
18231
  <span id="cl-discard-modal-title">Discard Changes</span>
17016
18232
  <button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="close-modal" title="Close" aria-label="Close">&times;</button>
17017
18233
  </div>
17018
18234
  <div class="codelab-modal__body">
17019
- <p id="cl-discard-modal-desc" style="margin:0 0 14px;font-size:13px;line-height:1.5;">${escapeHtml(desc)}</p>
18235
+ <p id="cl-discard-modal-desc" class="cl-ui-modal-desc">${escapeHtml(desc)}</p>
17020
18236
  <div style="display:flex;justify-content:flex-end;gap:8px;">
17021
18237
  <button type="button" class="codelab-btn" id="cl-discard-cancel-btn" data-cl-action="close-modal">Cancel</button>
17022
18238
  <button type="button" class="codelab-btn codelab-btn--danger" id="cl-discard-confirm-btn">Discard Changes</button>
17023
18239
  </div>
17024
18240
  </div>
17025
18241
  </div>
17026
- </div>
18242
+ </dialog>
17027
18243
  `;
18244
+ this._openModalDialog(slot);
17028
18245
  const cancelBtn = slot.querySelector('#cl-discard-cancel-btn');
17029
18246
  const confirmBtn = slot.querySelector('#cl-discard-confirm-btn');
17030
18247
  if (cancelBtn && typeof cancelBtn.focus === 'function') {
@@ -17109,6 +18326,11 @@ int main() {
17109
18326
  } catch (_err) {
17110
18327
  void _err;
17111
18328
  }
18329
+ if (scmMod && typeof scmMod.syncToIsoGitRepo === 'function') {
18330
+ Promise.resolve(scmMod.syncToIsoGitRepo(this.shell.vfs, gs, '/workspace')).catch((_e) => {
18331
+ void _e;
18332
+ });
18333
+ }
17112
18334
  }
17113
18335
  if (this._activeScmDiffFile) {
17114
18336
  const remaining = this.getGitStatus();
@@ -17119,6 +18341,8 @@ int main() {
17119
18341
  this._syncActiveFileToView();
17120
18342
  }
17121
18343
  }
18344
+ this._updateEditorGitGutter();
18345
+ this._renderFileLists();
17122
18346
  this._syncFilesToShellVfs({ keepGitDir: true });
17123
18347
  this._saveState();
17124
18348
  }
@@ -17144,6 +18368,7 @@ int main() {
17144
18368
  if (!cleanName || cleanName.startsWith('-') || cleanName.includes('..')) return false;
17145
18369
  const gs = this._getGitState();
17146
18370
  if (!gs) return false;
18371
+ const scmMod = root.CodeLabScm;
17147
18372
  if (!(gs.branches instanceof Set)) {
17148
18373
  gs.branches = new Set(Array.isArray(gs.branches) ? gs.branches : [gs.branch || 'main']);
17149
18374
  }
@@ -17173,6 +18398,11 @@ int main() {
17173
18398
  } catch (_err) {
17174
18399
  void _err;
17175
18400
  }
18401
+ if (scmMod && typeof scmMod.syncToIsoGitRepo === 'function') {
18402
+ Promise.resolve(scmMod.syncToIsoGitRepo(this.shell.vfs, gs, '/workspace')).catch((_e) => {
18403
+ void _e;
18404
+ });
18405
+ }
17176
18406
  }
17177
18407
  if (checkout) {
17178
18408
  return this.checkoutGitBranch(cleanName);
@@ -17188,26 +18418,42 @@ int main() {
17188
18418
  if (!cleanName) return false;
17189
18419
  const gs = this._getGitState();
17190
18420
  if (!gs) return false;
18421
+ const scmMod = root.CodeLabScm;
17191
18422
  if (!(gs.branches instanceof Set)) {
17192
18423
  gs.branches = new Set(Array.isArray(gs.branches) ? gs.branches : [gs.branch || 'main']);
17193
18424
  }
17194
18425
  if (!gs.branches.has(cleanName)) return false;
17195
- if (!gs.branchHeads || typeof gs.branchHeads !== 'object') gs.branchHeads = {};
17196
- const prevBranch = gs.branch || 'main';
17197
- if (prevBranch !== cleanName) {
17198
- gs.branchHeads[prevBranch] = {
17199
- headCommit: gs.headCommit || '',
17200
- headSnapshot: { ...(gs.headSnapshot || gs.headFiles || {}) },
17201
- commits: Array.isArray(gs.commits) ? gs.commits.slice() : []
17202
- };
17203
- const targetInfo = gs.branchHeads[cleanName];
17204
- if (targetInfo && typeof targetInfo === 'object') {
17205
- gs.headCommit = targetInfo.headCommit || '';
17206
- this._syncGitHeadState(gs, targetInfo.headSnapshot || {});
17207
- gs.commits = Array.isArray(targetInfo.commits) ? targetInfo.commits.slice() : [];
18426
+
18427
+ let switchedViaScm = false;
18428
+ if (scmMod && typeof scmMod.checkoutBranch === 'function') {
18429
+ const res = scmMod.checkoutBranch(this.shell || { gitState: gs, cwd: '/workspace' }, cleanName, this.files);
18430
+ if (res && res.ok) {
18431
+ switchedViaScm = true;
18432
+ } else if (res && !res.ok && res.error) {
18433
+ this._showToast(res.error, 'error');
18434
+ return false;
18435
+ }
18436
+ }
18437
+
18438
+ if (!switchedViaScm) {
18439
+ if (!gs.branchHeads || typeof gs.branchHeads !== 'object') gs.branchHeads = {};
18440
+ const prevBranch = gs.branch || 'main';
18441
+ if (prevBranch !== cleanName) {
18442
+ gs.branchHeads[prevBranch] = {
18443
+ headCommit: gs.headCommit || '',
18444
+ headSnapshot: { ...(gs.headSnapshot || gs.headFiles || {}) },
18445
+ commits: Array.isArray(gs.commits) ? gs.commits.slice() : []
18446
+ };
18447
+ const targetInfo = gs.branchHeads[cleanName];
18448
+ if (targetInfo && typeof targetInfo === 'object') {
18449
+ gs.headCommit = targetInfo.headCommit || '';
18450
+ this._syncGitHeadState(gs, targetInfo.headSnapshot || {});
18451
+ gs.commits = Array.isArray(targetInfo.commits) ? targetInfo.commits.slice() : [];
18452
+ }
17208
18453
  }
18454
+ gs.branch = cleanName;
17209
18455
  }
17210
- gs.branch = cleanName;
18456
+
17211
18457
  if (this.shell && this.shell.vfs && typeof this.shell.vfs.writeFileSync === 'function') {
17212
18458
  try {
17213
18459
  if (typeof this.shell.vfs.mkdirSync === 'function') {
@@ -17217,14 +18463,29 @@ int main() {
17217
18463
  } catch (_err) {
17218
18464
  void _err;
17219
18465
  }
18466
+ if (scmMod && typeof scmMod.syncToIsoGitRepo === 'function') {
18467
+ Promise.resolve(scmMod.syncToIsoGitRepo(this.shell.vfs, gs, '/workspace')).catch((_e) => {
18468
+ void _e;
18469
+ });
18470
+ }
17220
18471
  }
18472
+ if (Array.isArray(this.openTabs)) {
18473
+ this.openTabs = this.openTabs.filter((t) => Object.prototype.hasOwnProperty.call(this.files, t));
18474
+ }
18475
+ if (this.activeFile && !Object.prototype.hasOwnProperty.call(this.files, this.activeFile)) {
18476
+ this.activeFile = this.openTabs[0] || this._pickDefaultFile() || null;
18477
+ if (this.activeTab !== '__settings__' && this.activeTab !== '__welcome__') {
18478
+ this.activeTab = this.activeFile;
18479
+ }
18480
+ }
18481
+ this._syncFilesToShellVfs({ pruneExtraneous: true, keepGitDir: true });
18482
+ this._syncAllModels();
17221
18483
  this._saveState();
17222
18484
  if (this.activeSidebarView === 'scm') {
17223
18485
  this._renderScmSidebar();
17224
18486
  }
17225
- if (this._activeScmDiffFile) {
17226
- this._syncActiveFileToView();
17227
- }
18487
+ this._syncActiveFileToView();
18488
+ this._updateEditorGitGutter();
17228
18489
  this._updateStatusBar();
17229
18490
  return true;
17230
18491
  }
@@ -17245,7 +18506,7 @@ int main() {
17245
18506
  openScmDiff(relPath, opts = {}) {
17246
18507
  const cleanRel = String(relPath || '').trim().replace(/^\/+/, '');
17247
18508
  if (!cleanRel) return false;
17248
- if (this.activeTab === '__settings__') {
18509
+ if (this.activeTab === '__settings__' || this.activeTab === '__welcome__') {
17249
18510
  this.activeTab = this.activeFile || null;
17250
18511
  }
17251
18512
  this._activeScmDiffFile = cleanRel;
@@ -17258,6 +18519,9 @@ int main() {
17258
18519
  if (!this._activeScmDiffFile) return false;
17259
18520
  this._activeScmDiffFile = null;
17260
18521
  this._activeScmDiffStaged = false;
18522
+ if (this._scmDiffManager && typeof this._scmDiffManager.closeInlineDiff === 'function') {
18523
+ try { this._scmDiffManager.closeInlineDiff(); } catch (_err) { void _err; }
18524
+ }
17261
18525
  this._syncActiveFileToView();
17262
18526
  return true;
17263
18527
  }
@@ -17285,6 +18549,58 @@ int main() {
17285
18549
  const rightLabel = isStaged ? `Index (Staged): ${relPath}` : `Working Tree: ${relPath}`;
17286
18550
  const diff = this._computeLineDiff(leftText, rightText);
17287
18551
  const hasFileInWorktree = Object.prototype.hasOwnProperty.call(this.files, relPath);
18552
+ const canUseMonacoDiff = Boolean(
18553
+ !this._scmForceUnifiedDiff &&
18554
+ this.monaco &&
18555
+ this.monaco.editor &&
18556
+ typeof this.monaco.editor.createDiffEditor === 'function' &&
18557
+ _wbComponents &&
18558
+ typeof _wbComponents.CodeLabDiffEditorManager === 'function'
18559
+ );
18560
+
18561
+ if (this._scmDiffManager && typeof this._scmDiffManager.closeInlineDiff === 'function') {
18562
+ try { this._scmDiffManager.closeInlineDiff(); } catch (_err) { void _err; }
18563
+ }
18564
+
18565
+ const headerHtml = `
18566
+ <div class="codelab-scm-diff-header">
18567
+ <div class="codelab-scm-diff-header__title">
18568
+ <strong>${escapeHtml(relPath)}</strong>
18569
+ <span class="codelab-scm-diff-header__meta">${escapeHtml(leftLabel)} &rarr; ${escapeHtml(rightLabel)}</span>
18570
+ <span class="codelab-scm-diff-stats">
18571
+ <span class="codelab-scm-diff-stats__add">+${diff.added}</span>
18572
+ <span class="codelab-scm-diff-stats__del">−${diff.removed}</span>
18573
+ </span>
18574
+ </div>
18575
+ <div class="codelab-scm-diff-header__actions">
18576
+ ${this.monaco && this.monaco.editor && typeof this.monaco.editor.createDiffEditor === 'function'
18577
+ ? `<button type="button" class="codelab-btn" data-cl-action="scm-toggle-diff-mode" title="Toggle Side-by-Side / Inline Diff">${this._scmForceUnifiedDiff ? 'Side-by-Side' : 'Inline'}</button>`
18578
+ : ''}
18579
+ ${hasFileInWorktree ? `<button type="button" class="codelab-btn" data-cl-action="scm-diff-open-editor" data-scm-path="${escapeHtml(relPath)}" title="Open File in Editor">Open File</button>` : ''}
18580
+ <button type="button" class="codelab-btn" data-cl-action="scm-close-diff" title="Close Diff View" aria-label="Close Diff">Close Diff</button>
18581
+ </div>
18582
+ </div>
18583
+ `;
18584
+
18585
+ if (canUseMonacoDiff) {
18586
+ hostEl.innerHTML = `${headerHtml}<div class="codelab-scm-monaco-diff" style="flex:1;min-height:0;position:relative;"></div>`;
18587
+ const monacoDiffSlot = hostEl.querySelector('.codelab-scm-monaco-diff');
18588
+ if (monacoDiffSlot) {
18589
+ if (!this._scmDiffManager) {
18590
+ this._scmDiffManager = new _wbComponents.CodeLabDiffEditorManager(this);
18591
+ }
18592
+ const mounted = typeof this._scmDiffManager.mountMonacoDiffIntoSlot === 'function'
18593
+ ? this._scmDiffManager.mountMonacoDiffIntoSlot(monacoDiffSlot, {
18594
+ relPath,
18595
+ originalContent: leftText,
18596
+ modifiedContent: rightText,
18597
+ sideBySide: true,
18598
+ readOnly: true
18599
+ })
18600
+ : false;
18601
+ if (mounted) return;
18602
+ }
18603
+ }
17288
18604
 
17289
18605
  const linesHtml = diff.hunks.map((h) => {
17290
18606
  const cls = h.type === 'add'
@@ -17302,20 +18618,7 @@ int main() {
17302
18618
  }).join('');
17303
18619
 
17304
18620
  hostEl.innerHTML = `
17305
- <div class="codelab-scm-diff-header">
17306
- <div class="codelab-scm-diff-header__title">
17307
- <strong>${escapeHtml(relPath)}</strong>
17308
- <span class="codelab-scm-diff-header__meta">${escapeHtml(leftLabel)} &rarr; ${escapeHtml(rightLabel)}</span>
17309
- <span class="codelab-scm-diff-stats">
17310
- <span class="codelab-scm-diff-stats__add">+${diff.added}</span>
17311
- <span class="codelab-scm-diff-stats__del">−${diff.removed}</span>
17312
- </span>
17313
- </div>
17314
- <div class="codelab-scm-diff-header__actions">
17315
- ${hasFileInWorktree ? `<button type="button" class="codelab-btn" data-cl-action="scm-diff-open-editor" data-scm-path="${escapeHtml(relPath)}" title="Open File in Editor">Open File</button>` : ''}
17316
- <button type="button" class="codelab-btn" data-cl-action="scm-close-diff" title="Close Diff View" aria-label="Close Diff">Close Diff</button>
17317
- </div>
17318
- </div>
18621
+ ${headerHtml}
17319
18622
  <div class="codelab-scm-diff-body codelab-diff-unified">
17320
18623
  ${linesHtml || '<div class="codelab-sidebar-empty">No line differences.</div>'}
17321
18624
  </div>
@@ -18366,8 +19669,10 @@ int main() {
18366
19669
  this._renderDrawerBody();
18367
19670
  } else if (cmd === 'terminal:kill') {
18368
19671
  this.killActiveTerminalSession();
19672
+ } else if (cmd === 'terminal:split') {
19673
+ this.splitActiveTerminalSession();
18369
19674
  } else if (cmd === 'help:welcome') {
18370
- this.closeAllTabs();
19675
+ this.openWelcomeTab();
18371
19676
  } else if (cmd === 'help:shortcuts') {
18372
19677
  this.showKeyboardShortcutsReference();
18373
19678
  } else if (cmd === 'help:about') {
@@ -18459,12 +19764,12 @@ int main() {
18459
19764
  this._captureModalReturnFocus();
18460
19765
  const rowsHtml = list.length > 0
18461
19766
  ? list.map((ws) => `
18462
- <button type="button" class="codelab-recent-ws-item" data-cl-workspace="${escapeHtml(ws.labId)}" style="display:flex;width:100%;align-items:center;justify-content:space-between;padding:8px 10px;border:1px solid var(--cl-border);border-radius:var(--cl-radius-sm);background:var(--cl-surface);color:var(--cl-fg);cursor:pointer;text-align:left;">
19767
+ <button type="button" class="codelab-recent-ws-item" data-cl-workspace="${escapeHtml(ws.labId)}">
18463
19768
  <span>
18464
19769
  <strong>${escapeHtml(ws.title || ws.labId)}</strong>
18465
- ${ws.labId === this.labId ? '<span style="opacity:0.7;margin-left:6px;">(Current)</span>' : ''}
19770
+ ${ws.labId === this.labId ? '<span class="cl-ui-meta-inline">(Current)</span>' : ''}
18466
19771
  </span>
18467
- <code style="font-size:11px;opacity:0.75;">${escapeHtml(ws.labId)}</code>
19772
+ <code class="cl-ui-chip">${escapeHtml(ws.labId)}</code>
18468
19773
  </button>
18469
19774
  `).join('')
18470
19775
  : '<p style="margin:0;color:var(--cl-fg-muted);">No saved workspaces found yet.</p>';
@@ -18932,8 +20237,8 @@ int main() {
18932
20237
  <button type="button" class="codelab-btn" data-cl-action="close-modal">Close (Esc)</button>
18933
20238
  </div>
18934
20239
  <div class="codelab-modal__body">
18935
- <div style="display:grid;grid-template-columns:1fr auto;gap:6px 16px;font-size:12px;">
18936
- ${rows.map(([label, kbd]) => `<span>${escapeHtml(label)}</span><kbd style="font-family:var(--cl-font-mono);">${escapeHtml(kbd)}</kbd>`).join('')}
20240
+ <div class="cl-ui-shortcuts-grid">
20241
+ ${rows.map(([label, kbd]) => `<span>${escapeHtml(label)}</span><kbd class="cl-ui-kbd">${escapeHtml(kbd)}</kbd>`).join('')}
18937
20242
  </div>
18938
20243
  </div>
18939
20244
  </div>
@@ -18948,19 +20253,20 @@ int main() {
18948
20253
  if (!slot) return;
18949
20254
  this._captureModalReturnFocus();
18950
20255
  slot.innerHTML = `
18951
- <div class="codelab-modal-backdrop">
18952
- <div class="codelab-modal" role="dialog" aria-modal="true" aria-label="About CodeLab" style="max-width:420px;">
20256
+ <dialog class="codelab-dialog" closedby="any" aria-label="About CodeLab" style="max-width:420px;">
20257
+ <div class="codelab-modal" role="document">
18953
20258
  <div class="codelab-modal__header">
18954
20259
  <span>About CodeLab</span>
18955
20260
  <button type="button" class="codelab-btn" data-cl-action="close-modal">Close (Esc)</button>
18956
20261
  </div>
18957
- <div class="codelab-modal__body" style="font-size:13px;line-height:1.5;">
18958
- <p style="margin:0 0 8px;"><strong>@innovatorved/code-lab</strong> — Full-featured in-browser IDE &amp; runtime workbench.</p>
18959
- <p style="margin:0;color:var(--cl-fg-muted);font-size:12px;">Node.js v22 Worker · TypeScript 5.x · C++20 WASI · Python 3.12 WASI · SQLite / PostgreSQL</p>
20262
+ <div class="codelab-modal__body">
20263
+ <p class="cl-ui-body-p"><strong>@innovatorved/code-lab</strong> — Full-featured in-browser IDE &amp; runtime workbench.</p>
20264
+ <p class="cl-ui-muted-note">Node.js v22 Worker · TypeScript 5.x · C++20 WASI · Python 3.12 WASI · SQLite / PostgreSQL · Git</p>
18960
20265
  </div>
18961
20266
  </div>
18962
- </div>
20267
+ </dialog>
18963
20268
  `;
20269
+ this._openModalDialog(slot);
18964
20270
  const closeBtn = slot.querySelector('[data-cl-action="close-modal"]');
18965
20271
  if (closeBtn && typeof closeBtn.focus === 'function') closeBtn.focus();
18966
20272
  }
@@ -18974,6 +20280,10 @@ int main() {
18974
20280
  active.logs = fresh;
18975
20281
  }
18976
20282
  }
20283
+ const activeXt = this._getActiveXtermEngine();
20284
+ if (activeXt && typeof activeXt.clear === 'function') {
20285
+ try { activeXt.clear(); } catch (_err) { void _err; }
20286
+ }
18977
20287
  }
18978
20288
 
18979
20289
  _renderTerminalSessionsBar() {
@@ -19114,6 +20424,16 @@ int main() {
19114
20424
  try { this._activeCommandAbortController.abort(); } catch (_err) { void _err; }
19115
20425
  this._activeCommandAbortController = null;
19116
20426
  }
20427
+ if (this._xtermEngines instanceof Map) {
20428
+ const oldEng = this._xtermEngines.get(sessions[0].id);
20429
+ if (oldEng && typeof oldEng.destroy === 'function') {
20430
+ try { oldEng.destroy(); } catch (_err) { void _err; }
20431
+ }
20432
+ this._xtermEngines.delete(sessions[0].id);
20433
+ }
20434
+ this._splitTerminalSessionIds = [];
20435
+ this._splitTerminalSessionId = null;
20436
+ this._xtermWrapLayoutKey = '';
19117
20437
  this.isRunning = false;
19118
20438
  const freshSession = {
19119
20439
  id: 'session-1',
@@ -19138,6 +20458,23 @@ int main() {
19138
20458
 
19139
20459
  this._saveActiveTerminalSessionState();
19140
20460
  const removed = sessions.splice(idx, 1)[0];
20461
+ if (this._xtermEngines instanceof Map && removed) {
20462
+ const oldEng = this._xtermEngines.get(removed.id);
20463
+ if (oldEng && typeof oldEng.destroy === 'function') {
20464
+ try { oldEng.destroy(); } catch (_err) { void _err; }
20465
+ }
20466
+ this._xtermEngines.delete(removed.id);
20467
+ }
20468
+ if (removed && this._splitTerminalSessionId === removed.id) {
20469
+ this._splitTerminalSessionId = null;
20470
+ }
20471
+ this._xtermWrapLayoutKey = '';
20472
+ if (Array.isArray(this._splitTerminalSessionIds) && removed) {
20473
+ this._splitTerminalSessionIds = this._splitTerminalSessionIds.filter((sid) => sid !== removed.id);
20474
+ if (this._splitTerminalSessionIds.length < 2) {
20475
+ this._splitTerminalSessionIds = [];
20476
+ }
20477
+ }
19141
20478
  if (this._activeTerminalSessionId === removed.id) {
19142
20479
  if (this._activeCommandAbortController) {
19143
20480
  try { this._activeCommandAbortController.abort(); } catch (_err) { void _err; }
@@ -19416,8 +20753,8 @@ int main() {
19416
20753
  <span id="cl-clone-modal-title" style="display:inline-flex;align-items:center;gap:6px;">${CL_ICONS.gitBranch || CL_ICONS.terminal || CL_ICONS.folder}<span>Clone Public GitHub Repository</span></span>
19417
20754
  <button type="button" class="codelab-btn" id="cl-clone-close-btn" data-cl-action="close-modal" aria-label="Close">✕</button>
19418
20755
  </div>
19419
- <div class="codelab-modal__body" style="font-family:var(--cl-font-sans);">
19420
- <p id="cl-clone-modal-desc" style="margin:0 0 12px;font-size:12.5px;color:var(--cl-fg-muted);line-height:1.45;">
20756
+ <div class="codelab-modal__body">
20757
+ <p id="cl-clone-modal-desc" class="cl-ui-modal-desc">
19421
20758
  Enter a public GitHub repository URL or <code>owner/repo</code> slug. Files are cloned transactionally into the Virtual Filesystem (VFS).
19422
20759
  </p>
19423
20760
  <form id="cl-clone-repo-form" class="codelab-clone-form" novalidate>
@@ -19845,6 +21182,11 @@ int main() {
19845
21182
  else gs.staged = new Map();
19846
21183
  if (gs.stagedFiles && typeof gs.stagedFiles.clear === 'function') gs.stagedFiles.clear();
19847
21184
  gs.commits = Array.isArray(result.commits) ? result.commits : [];
21185
+ if (root.CodeLabScm && typeof root.CodeLabScm.syncToIsoGitRepo === 'function' && this.shell && this.shell.vfs) {
21186
+ Promise.resolve(root.CodeLabScm.syncToIsoGitRepo(this.shell.vfs, gs, targetDir)).catch((_e) => {
21187
+ void _e;
21188
+ });
21189
+ }
19848
21190
  }
19849
21191
 
19850
21192
  this._updateTopbarBrandTitle();
@@ -20099,6 +21441,34 @@ int main() {
20099
21441
  this._editorResizeObserver.disconnect();
20100
21442
  this._editorResizeObserver = null;
20101
21443
  }
21444
+ if (typeof this._systemSchemeCleanup === 'function') {
21445
+ try { this._systemSchemeCleanup(); } catch (_err) { void _err; }
21446
+ this._systemSchemeCleanup = null;
21447
+ }
21448
+ if (this._ataController && typeof this._ataController.dispose === 'function') {
21449
+ try { this._ataController.dispose(); } catch (_err) { void _err; }
21450
+ this._ataController = null;
21451
+ }
21452
+ if (this._editorOpenerDisposable && typeof this._editorOpenerDisposable.dispose === 'function') {
21453
+ try { this._editorOpenerDisposable.dispose(); } catch (_err) { void _err; }
21454
+ this._editorOpenerDisposable = null;
21455
+ }
21456
+ if (this._autoCloseTagDisposable && typeof this._autoCloseTagDisposable.dispose === 'function') {
21457
+ try { this._autoCloseTagDisposable.dispose(); } catch (_err) { void _err; }
21458
+ this._autoCloseTagDisposable = null;
21459
+ }
21460
+ if (this._xtermEngines instanceof Map) {
21461
+ for (const eng of this._xtermEngines.values()) {
21462
+ if (eng && typeof eng.destroy === 'function') {
21463
+ try { eng.destroy(); } catch (_err) { void _err; }
21464
+ }
21465
+ }
21466
+ this._xtermEngines.clear();
21467
+ }
21468
+ if (this._scmDiffManager && typeof this._scmDiffManager.closeInlineDiff === 'function') {
21469
+ try { this._scmDiffManager.closeInlineDiff(); } catch (_err) { void _err; }
21470
+ this._scmDiffManager = null;
21471
+ }
20102
21472
  if (this._diffManager && typeof this._diffManager.closeInlineDiff === 'function') {
20103
21473
  try {
20104
21474
  this._diffManager.closeInlineDiff();
@@ -20238,6 +21608,8 @@ int main() {
20238
21608
  });
20239
21609
  }
20240
21610
 
21611
+ get vfs() { return this._instance ? this._instance.vfs : null; }
21612
+ get shell() { return this._instance ? this._instance.shell : null; }
20241
21613
  getFiles() { return this._instance ? this._instance.getFiles() : {}; }
20242
21614
  setFiles(filesMap, opts) { return this._instance ? this._instance.setFiles(filesMap, opts) : undefined; }
20243
21615
  getFile(path) { return this._instance ? this._instance.getFile(path) : null; }
@@ -20323,6 +21695,7 @@ int main() {
20323
21695
  toggleTerminal() { if (this._instance) this._instance.toggleTerminal(); }
20324
21696
  listTerminalSessions() { return this._instance ? this._instance.listTerminalSessions() : []; }
20325
21697
  createTerminalSession(name) { return this._instance ? this._instance.createTerminalSession(name) : null; }
21698
+ splitActiveTerminalSession() { return this._instance ? this._instance.splitActiveTerminalSession() : null; }
20326
21699
  switchTerminalSession(id) { return this._instance ? this._instance.switchTerminalSession(id) : false; }
20327
21700
  closeTerminalSession(id) { return this._instance ? this._instance.closeTerminalSession(id) : false; }
20328
21701
  killActiveTerminalSession() { return this._instance ? this._instance.killActiveTerminalSession() : false; }
@@ -20333,6 +21706,8 @@ int main() {
20333
21706
  openBlankWorkspace(opts) { return this._instance ? this._instance.openBlankWorkspace(opts) : Promise.resolve(null); }
20334
21707
  newBlankWorkspace(title) { return this._instance ? this._instance.newBlankWorkspace(title) : null; }
20335
21708
  switchWorkspace(id, opts) { return this._instance ? this._instance.switchWorkspace(id, opts) : Promise.resolve(false); }
21709
+ openWelcomeTab() { if (this._instance) this._instance.openWelcomeTab(); }
21710
+ closeWelcomeTab() { if (this._instance) this._instance.closeWelcomeTab(); }
20336
21711
  openSettings(opts) { if (this._instance) this._instance.openSettings(opts); }
20337
21712
  closeSettings() { if (this._instance) this._instance.closeSettings(); }
20338
21713
  openWorkspaceSettingsJson() { if (this._instance) this._instance.openWorkspaceSettingsJson(); }