@innovatorved/code-lab 0.3.1 → 0.4.0

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 (171) hide show
  1. package/ARCHITECTURE.md +8 -4
  2. package/CHANGELOG.md +45 -0
  3. package/README.md +70 -158
  4. package/dist/apps/web/src/index.d.ts +34 -0
  5. package/dist/code-lab-sql.css +482 -0
  6. package/dist/code-lab-sql.d.ts +179 -0
  7. package/dist/code-lab-sql.esm.js +542 -0
  8. package/dist/code-lab-sql.umd.js +531 -0
  9. package/dist/code-lab.css +298 -2
  10. package/dist/code-lab.d.ts +110 -15
  11. package/dist/code-lab.esm.js +35284 -18253
  12. package/dist/code-lab.js +40434 -23431
  13. package/dist/code-lab.umd.js +65502 -0
  14. package/dist/diagnostics.d.ts +5 -0
  15. package/dist/extensions/cpp.esm.js +19532 -3772
  16. package/dist/extensions/cpp.js +19529 -3769
  17. package/dist/extensions/guided-lab.esm.js +19401 -3725
  18. package/dist/extensions/guided-lab.js +19400 -3724
  19. package/dist/extensions/python.d.ts +1 -0
  20. package/dist/extensions/python.esm.js +19666 -3843
  21. package/dist/extensions/python.js +19668 -3845
  22. package/dist/extensions/umbrella.d.ts +5 -0
  23. package/dist/index.d.ts +1 -1
  24. package/dist/modular-kernel.d.ts +11 -0
  25. package/dist/packages/commands/src/index.d.ts +96 -0
  26. package/dist/packages/core/src/di.d.ts +36 -0
  27. package/dist/packages/core/src/disposable.d.ts +27 -0
  28. package/dist/packages/core/src/errors.d.ts +69 -0
  29. package/dist/packages/core/src/events.d.ts +38 -0
  30. package/dist/packages/core/src/index.d.ts +6 -0
  31. package/dist/packages/core/src/path.d.ts +14 -0
  32. package/dist/packages/core/src/registry.d.ts +23 -0
  33. package/dist/packages/editor/src/index.d.ts +118 -0
  34. package/dist/packages/fs/src/backends.d.ts +37 -0
  35. package/dist/packages/fs/src/index.d.ts +3 -0
  36. package/dist/packages/fs/src/types.d.ts +40 -0
  37. package/dist/packages/fs/src/vfs-service.d.ts +33 -0
  38. package/dist/packages/preview/src/index.d.ts +34 -0
  39. package/dist/packages/runtime/src/index.d.ts +47 -0
  40. package/dist/packages/settings/src/builtin-schemas.d.ts +15 -0
  41. package/dist/packages/settings/src/configuration-service.d.ts +100 -0
  42. package/dist/packages/settings/src/index.d.ts +4 -0
  43. package/dist/packages/settings/src/jsonc.d.ts +20 -0
  44. package/dist/packages/settings/src/schema.d.ts +28 -0
  45. package/dist/packages/sql/src/completions.d.ts +8 -0
  46. package/dist/packages/sql/src/diagnostics.d.ts +2 -0
  47. package/dist/packages/sql/src/formatter.d.ts +2 -0
  48. package/dist/packages/sql/src/index.d.ts +7 -0
  49. package/dist/packages/sql/src/sql-editor.d.ts +2 -0
  50. package/dist/packages/sql/src/styles.d.ts +2 -0
  51. package/dist/packages/sql/src/tokenizer.d.ts +13 -0
  52. package/dist/packages/sql/src/types.d.ts +130 -0
  53. package/dist/packages/terminal/src/index.d.ts +54 -0
  54. package/dist/packages/ui/src/index.d.ts +4 -0
  55. package/dist/packages/ui/src/observability.d.ts +22 -0
  56. package/dist/packages/ui/src/plugin-registry.d.ts +89 -0
  57. package/dist/packages/ui/src/settings-dialog.d.ts +25 -0
  58. package/dist/packages/ui/src/themes.d.ts +35 -0
  59. package/dist/preview-sw.js +82 -24
  60. package/dist/runtime.d.ts +3 -3
  61. package/dist/runtime.esm.js +503 -73
  62. package/dist/runtime.js +501 -73
  63. package/dist/schemas.d.ts +234 -814
  64. package/dist/schemas.esm.js +19401 -3725
  65. package/dist/schemas.js +19404 -3728
  66. package/dist/scm.d.ts +13 -2
  67. package/dist/search.d.ts +5 -1
  68. package/dist/shell.d.ts +1 -1
  69. package/dist/shell.esm.js +435 -54
  70. package/dist/shell.js +435 -54
  71. package/dist/terminal.esm.js +242 -54
  72. package/dist/terminal.js +242 -54
  73. package/dist/workbench/diff-editor.d.ts +1 -0
  74. package/dist/workbench/index.d.ts +1 -1
  75. package/dist/workbench/styles.d.ts +1 -1
  76. package/dist/zip.d.ts +4 -3
  77. package/package.json +37 -8
  78. package/packages/commands/README.md +7 -0
  79. package/packages/commands/package.json +16 -0
  80. package/packages/commands/src/index.ts +467 -0
  81. package/packages/commands/tsconfig.json +22 -0
  82. package/packages/core/README.md +12 -0
  83. package/packages/core/package.json +13 -0
  84. package/packages/core/src/di.ts +147 -0
  85. package/packages/core/src/disposable.ts +112 -0
  86. package/packages/core/src/errors.ts +205 -0
  87. package/packages/core/src/events.ts +157 -0
  88. package/packages/core/src/index.ts +49 -0
  89. package/packages/core/src/path.ts +118 -0
  90. package/packages/core/src/registry.ts +61 -0
  91. package/packages/core/tsconfig.json +19 -0
  92. package/packages/editor/README.md +9 -0
  93. package/packages/editor/package.json +18 -0
  94. package/packages/editor/src/index.ts +344 -0
  95. package/packages/editor/tsconfig.json +24 -0
  96. package/packages/fs/README.md +7 -0
  97. package/packages/fs/package.json +16 -0
  98. package/packages/fs/src/backends.ts +301 -0
  99. package/packages/fs/src/index.ts +18 -0
  100. package/packages/fs/src/types.ts +44 -0
  101. package/packages/fs/src/vfs-service.ts +257 -0
  102. package/packages/fs/tsconfig.json +22 -0
  103. package/packages/preview/README.md +3 -0
  104. package/packages/preview/package.json +16 -0
  105. package/packages/preview/src/index.ts +125 -0
  106. package/packages/preview/tsconfig.json +22 -0
  107. package/packages/runtime/README.md +3 -0
  108. package/packages/runtime/package.json +17 -0
  109. package/packages/runtime/src/index.ts +134 -0
  110. package/packages/runtime/tsconfig.json +23 -0
  111. package/packages/settings/README.md +7 -0
  112. package/packages/settings/package.json +16 -0
  113. package/packages/settings/src/builtin-schemas.ts +235 -0
  114. package/packages/settings/src/configuration-service.ts +543 -0
  115. package/packages/settings/src/index.ts +37 -0
  116. package/packages/settings/src/jsonc.ts +189 -0
  117. package/packages/settings/src/schema.ts +164 -0
  118. package/packages/settings/tsconfig.json +22 -0
  119. package/packages/sql/README.md +12 -0
  120. package/packages/sql/package.json +13 -0
  121. package/packages/sql/src/completions.ts +359 -0
  122. package/packages/sql/src/diagnostics.ts +200 -0
  123. package/packages/sql/src/formatter.ts +271 -0
  124. package/packages/sql/src/index.ts +54 -0
  125. package/packages/sql/src/sql-editor.ts +802 -0
  126. package/packages/sql/src/styles.ts +501 -0
  127. package/packages/sql/src/tokenizer.ts +457 -0
  128. package/packages/sql/src/types.ts +148 -0
  129. package/packages/sql/tsconfig.json +19 -0
  130. package/packages/terminal/README.md +3 -0
  131. package/packages/terminal/package.json +16 -0
  132. package/packages/terminal/src/index.ts +183 -0
  133. package/packages/terminal/tsconfig.json +22 -0
  134. package/packages/ui/README.md +8 -0
  135. package/packages/ui/package.json +18 -0
  136. package/packages/ui/src/index.ts +36 -0
  137. package/packages/ui/src/observability.ts +175 -0
  138. package/packages/ui/src/plugin-registry.ts +274 -0
  139. package/packages/ui/src/settings-dialog.ts +293 -0
  140. package/packages/ui/src/themes.ts +174 -0
  141. package/packages/ui/tsconfig.json +24 -0
  142. package/src/code-lab.css +298 -2
  143. package/src/csp.ts +7 -10
  144. package/src/diagnostics.ts +42 -3
  145. package/src/extensions/cpp.ts +105 -24
  146. package/src/extensions/python.ts +260 -116
  147. package/src/extensions/umbrella.ts +5 -0
  148. package/src/index.ts +1 -1
  149. package/src/modular-kernel.ts +11 -0
  150. package/src/preview-sw.js +73 -12
  151. package/src/runtime.ts +501 -74
  152. package/src/schemas.ts +62 -62
  153. package/src/scm.ts +106 -19
  154. package/src/search.ts +71 -27
  155. package/src/shell.ts +433 -53
  156. package/src/terminal.ts +239 -52
  157. package/src/workbench/diff-editor.ts +106 -18
  158. package/src/workbench/drawer.ts +17 -4
  159. package/src/workbench/guided-pane.ts +12 -2
  160. package/src/workbench/icons.ts +5 -2
  161. package/src/workbench/share.ts +37 -8
  162. package/src/workbench/styles.ts +2 -1
  163. package/src/workbench/toolbar.ts +15 -4
  164. package/src/workbench.ts +2877 -284
  165. package/src/zip.ts +29 -7
  166. package/dist/runtime/index.d.ts +0 -4
  167. package/dist/shell/coreutils/compilers-cli.d.ts +0 -24
  168. package/dist/shell/index.d.ts +0 -4
  169. package/src/runtime/index.ts +0 -5
  170. package/src/shell/coreutils/compilers-cli.ts +0 -103
  171. package/src/shell/index.ts +0 -5
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * ============================================================
3
- * @innovatorved/code-lab v0.3.1 — Standalone Browser Code IDE & Virtual Runtime
3
+ * @innovatorved/code-lab v0.4.0 — Standalone Browser Code IDE & Virtual Runtime
4
4
  * ============================================================
5
5
  * Features:
6
6
  * - Sandboxed Web Worker Execution Engine with Multi-Instance Isolation & Watchdog Timer
7
7
  * - First-Class Node.js and Bun Runtimes (Bun.serve, bun:test, bun:sqlite, Bun.*)
8
- * - Full POSIX Shell AST & 55+ UNIX Coreutils (pipes, redirects, globs, env vars, git & git clone)
8
+ * - Full POSIX Shell AST & 71 UNIX Coreutils (pipes, redirects, globs, env vars, git & git clone)
9
9
  * - Interactive PTY Terminal Emulator with inline prompt, Tab completion & ANSI colors
10
10
  * - Persistent HTTP/TCP Servers, CLI curl & Live Port/HTTP Preview
11
11
  * - Modular VS Code Workbench: File Tree, Tabs, Command Palette, Diff Viewer
@@ -86,6 +86,7 @@ var CodeLabLogger = (() => {
86
86
  } catch (err) {
87
87
  sinkError = err;
88
88
  }
89
+ void sinkError;
89
90
  }
90
91
  const consoleObj = typeof console !== "undefined" ? console : null;
91
92
  const fn = consoleObj ? consoleObj[level] : null;
@@ -422,6 +423,14 @@ var CodeLabLogger = (() => {
422
423
 
423
424
  const parseAnsiToHtml = ansiToHtml;
424
425
 
426
+ const MAX_SCROLLBACK = 2000;
427
+ const VALID_LOG_TYPES = new Set(['stdout', 'stderr', 'system', 'info', 'warn', 'error', 'success']);
428
+
429
+ function sanitizeLogType(type) {
430
+ const t = String(type || 'stdout').trim();
431
+ return VALID_LOG_TYPES.has(t) ? t : 'stdout';
432
+ }
433
+
425
434
  class PTYTerminalEngine {
426
435
  constructor(container, options = {}) {
427
436
  if (
@@ -436,6 +445,12 @@ var CodeLabLogger = (() => {
436
445
  }
437
446
  this.container = container || null;
438
447
  this.options = options || {};
448
+ this.maxScrollback = typeof this.options.maxScrollback === 'number' && this.options.maxScrollback > 0
449
+ ? this.options.maxScrollback
450
+ : MAX_SCROLLBACK;
451
+ this.maxHistory = typeof this.options.maxHistory === 'number' && this.options.maxHistory > 0
452
+ ? this.options.maxHistory
453
+ : 1000;
439
454
  this.logs = Array.isArray(this.options.logs) ? this.options.logs : [];
440
455
  this.cwd = this.options.cwd || '/workspace';
441
456
  this.replMode = Boolean(this.options.replMode);
@@ -449,6 +464,7 @@ var CodeLabLogger = (() => {
449
464
  this.searchQuery = '';
450
465
  this.searchMatchIdx = -1;
451
466
  this._readLineQueue = [];
467
+ this.isBusy = false;
452
468
  this.onCommand = typeof this.options.onCommand === 'function' ? this.options.onCommand : null;
453
469
  this.getCompletions = typeof this.options.getCompletions === 'function' ? this.options.getCompletions : null;
454
470
  this.onKey = typeof this.options.onKey === 'function' ? this.options.onKey : null;
@@ -599,13 +615,40 @@ var CodeLabLogger = (() => {
599
615
  this.writeStreamChunk(String(data) + '\n', type);
600
616
  }
601
617
 
618
+ isCommandRunning() {
619
+ return Boolean(this.isBusy && (!this._readLineQueue || this._readLineQueue.length === 0));
620
+ }
621
+
622
+ _pushLog(entry) {
623
+ const normalized = {
624
+ type: sanitizeLogType(entry && entry.type),
625
+ text: String(entry && entry.text != null ? entry.text : '')
626
+ };
627
+ this.logs.push(normalized);
628
+ if (this.logs.length > this.maxScrollback) {
629
+ const excess = this.logs.length - this.maxScrollback;
630
+ this.logs.splice(0, excess);
631
+ if (this._targetLineIdx >= 0) {
632
+ this._targetLineIdx = Math.max(0, this._targetLineIdx - excess);
633
+ }
634
+ if (this.container && typeof this.container.querySelector === 'function') {
635
+ const logEl = this.container.querySelector('#cl-terminal-log');
636
+ if (logEl && logEl.children && logEl.children.length > this.maxScrollback) {
637
+ while (logEl.children.length > this.maxScrollback && typeof logEl.removeChild === 'function' && logEl.firstChild) {
638
+ logEl.removeChild(logEl.firstChild);
639
+ }
640
+ }
641
+ }
642
+ }
643
+ return normalized;
644
+ }
645
+
602
646
  _getActiveLine(type) {
603
647
  if (this._targetLineIdx >= 0 && this._targetLineIdx < this.logs.length) {
604
648
  return this.logs[this._targetLineIdx];
605
649
  }
606
650
  if (this._activeLineCommitted || this.logs.length === 0) {
607
- const newLine = { text: '', type };
608
- this.logs.push(newLine);
651
+ const newLine = this._pushLog({ text: '', type });
609
652
  this._activeLineCommitted = false;
610
653
  this._cursorCol = 0;
611
654
  this._targetLineIdx = this.logs.length - 1;
@@ -622,7 +665,7 @@ var CodeLabLogger = (() => {
622
665
  const logEl = this.container.querySelector('#cl-terminal-log');
623
666
  if (!logEl) return;
624
667
  const lineEl = document.createElement('div');
625
- lineEl.className = 'codelab-log-line ' + (line.type || 'stdout');
668
+ lineEl.className = 'codelab-log-line ' + sanitizeLogType(line.type);
626
669
  lineEl.innerHTML = ansiToHtml(line.text);
627
670
  logEl.appendChild(lineEl);
628
671
  this._activeLineEl = lineEl;
@@ -645,7 +688,7 @@ var CodeLabLogger = (() => {
645
688
  }
646
689
  }
647
690
  if (lineEl) {
648
- lineEl.className = 'codelab-log-line ' + (line.type || 'stdout');
691
+ lineEl.className = 'codelab-log-line ' + sanitizeLogType(line.type);
649
692
  lineEl.innerHTML = ansiToHtml(line.text);
650
693
  }
651
694
  }
@@ -684,17 +727,75 @@ var CodeLabLogger = (() => {
684
727
  return [...this.history];
685
728
  }
686
729
 
687
- readLine(promptText = '') {
688
- const prevPrompt = this.promptOverride;
689
- if (promptText) {
690
- this.setPrompt(promptText);
730
+ _activateNextReadLine() {
731
+ if (!this._readLineQueue || this._readLineQueue.length === 0) return;
732
+ const head = this._readLineQueue[0];
733
+ if (head && typeof head === 'object' && !head._activated) {
734
+ head._activated = true;
735
+ head.prevPrompt = this.promptOverride;
736
+ if (head.promptText) {
737
+ this.promptOverride = head.promptText;
738
+ }
739
+ }
740
+ }
741
+
742
+ _drainReadLineQueue(result = null) {
743
+ if (!Array.isArray(this._readLineQueue) || this._readLineQueue.length === 0) return;
744
+ const queued = this._readLineQueue.splice(0, this._readLineQueue.length);
745
+ let restoredPrompt = undefined;
746
+ for (const entry of queued) {
747
+ if (entry && typeof entry === 'object' && entry._activated && restoredPrompt === undefined) {
748
+ restoredPrompt = entry.prevPrompt;
749
+ }
750
+ if (entry && typeof entry.cleanup === 'function') {
751
+ entry.cleanup();
752
+ }
753
+ }
754
+ if (restoredPrompt !== undefined) {
755
+ this.promptOverride = restoredPrompt;
756
+ }
757
+ for (const entry of queued) {
758
+ if (typeof entry === 'function') {
759
+ try { entry(result); } catch (err) { _terminalLogger.debug('readLine callback threw during drain.', err); }
760
+ } else if (entry && typeof entry.resolve === 'function') {
761
+ try { entry.resolve(result); } catch (err) { _terminalLogger.debug('readLine resolve threw during drain.', err); }
762
+ }
763
+ }
764
+ }
765
+
766
+ readLine(promptText = '', options = {}) {
767
+ if (options && options.signal && options.signal.aborted) {
768
+ return Promise.resolve(null);
691
769
  }
692
770
  return new Promise((resolve) => {
693
- this._readLineQueue.push((line) => {
694
- this.promptOverride = prevPrompt;
695
- this.updateActiveLine();
696
- resolve(line);
697
- });
771
+ const item = {
772
+ promptText: String(promptText || ''),
773
+ prevPrompt: null,
774
+ _activated: false,
775
+ cleanup: null,
776
+ resolve
777
+ };
778
+ if (options && options.signal && typeof options.signal.addEventListener === 'function') {
779
+ const onAbort = () => {
780
+ const idx = this._readLineQueue.indexOf(item);
781
+ if (idx !== -1) {
782
+ this._readLineQueue.splice(idx, 1);
783
+ if (item._activated) {
784
+ this.promptOverride = item.prevPrompt;
785
+ this._activateNextReadLine();
786
+ }
787
+ this.updateActiveLine();
788
+ resolve(null);
789
+ }
790
+ };
791
+ options.signal.addEventListener('abort', onAbort, { once: true });
792
+ item.cleanup = () => {
793
+ try { options.signal.removeEventListener('abort', onAbort); } catch (err) { _terminalLogger.debug('readLine abort listener cleanup failed.', err); }
794
+ };
795
+ }
796
+ this._readLineQueue.push(item);
797
+ this._activateNextReadLine();
798
+ this.updateActiveLine();
698
799
  });
699
800
  }
700
801
 
@@ -735,6 +836,7 @@ var CodeLabLogger = (() => {
735
836
  }
736
837
 
737
838
  destroy() {
839
+ this._drainReadLineQueue(null);
738
840
  this._cleanupListeners();
739
841
  this._mounted = false;
740
842
  }
@@ -764,6 +866,10 @@ var CodeLabLogger = (() => {
764
866
  if (input) {
765
867
  this._addListener(input, 'keydown', (e) => this.handleKeyDown(e));
766
868
  this._addListener(input, 'input', () => {
869
+ if (this.isCommandRunning()) {
870
+ input.value = '';
871
+ return;
872
+ }
767
873
  if (input.value !== this.buffer) {
768
874
  this.buffer = input.value;
769
875
  this.cursor = typeof input.selectionStart === 'number' ? input.selectionStart : this.buffer.length;
@@ -805,6 +911,36 @@ var CodeLabLogger = (() => {
805
911
  const key = e.key;
806
912
  const isCtrl = Boolean(e.ctrlKey || e.metaKey);
807
913
 
914
+ if (isCtrl && (key === 'l' || key === 'L')) {
915
+ if (e.preventDefault) e.preventDefault();
916
+ this.clear();
917
+ return;
918
+ }
919
+
920
+ if (isCtrl && (key === 'c' || key === 'C')) {
921
+ if (e.preventDefault) e.preventDefault();
922
+ const wasBusy = this.isBusy || (this._readLineQueue && this._readLineQueue.length > 0);
923
+ this.isBusy = false;
924
+ this._pushLog({ type: 'system', text: wasBusy ? '^C' : `${this.getPrompt()}${this.buffer}^C` });
925
+ this.buffer = '';
926
+ this.cursor = 0;
927
+ this.historyIdx = -1;
928
+ this._drainReadLineQueue(null);
929
+ if (this.replMode) {
930
+ this.replMode = false;
931
+ }
932
+ if (this.onInterrupt) {
933
+ try { this.onInterrupt(); } catch (err) { _terminalLogger.warn('Terminal onInterrupt callback threw.', err); }
934
+ }
935
+ this.render();
936
+ return;
937
+ }
938
+
939
+ if (this.isCommandRunning()) {
940
+ if (e.preventDefault) e.preventDefault();
941
+ return;
942
+ }
943
+
808
944
  if (isCtrl && (key === 'r' || key === 'R')) {
809
945
  if (e.preventDefault) e.preventDefault();
810
946
  if (!this.searchMode) {
@@ -936,33 +1072,11 @@ var CodeLabLogger = (() => {
936
1072
  return;
937
1073
  }
938
1074
 
939
- if (isCtrl && (key === 'l' || key === 'L')) {
940
- if (e.preventDefault) e.preventDefault();
941
- this.clear();
942
- return;
943
- }
944
-
945
- if (isCtrl && (key === 'c' || key === 'C')) {
946
- if (e.preventDefault) e.preventDefault();
947
- this.logs.push({ type: 'system', text: `${this.getPrompt()}${this.buffer}^C` });
948
- this.buffer = '';
949
- this.cursor = 0;
950
- this.historyIdx = -1;
951
- if (this.replMode) {
952
- this.replMode = false;
953
- }
954
- if (this.onInterrupt) {
955
- try { this.onInterrupt(); } catch (err) { _terminalLogger.warn('Terminal onInterrupt callback threw.', err); }
956
- }
957
- this.render();
958
- return;
959
- }
960
-
961
1075
  if (isCtrl && (key === 'd' || key === 'D')) {
962
1076
  if (this.buffer === '') {
963
1077
  if (e.preventDefault) e.preventDefault();
964
1078
  if (this.replMode) {
965
- this.logs.push({ type: 'system', text: `${this.getPrompt()}.exit` });
1079
+ this._pushLog({ type: 'system', text: `${this.getPrompt()}.exit` });
966
1080
  this.replMode = false;
967
1081
  this.render();
968
1082
  return;
@@ -1056,14 +1170,44 @@ var CodeLabLogger = (() => {
1056
1170
  }
1057
1171
 
1058
1172
  // Print candidate matches
1059
- this.logs.push({ type: 'system', text: `${this.getPrompt()}${this.buffer}` });
1060
- this.logs.push({ type: 'stdout', text: matches.join(' ') });
1173
+ this._pushLog({ type: 'system', text: `${this.getPrompt()}${this.buffer}` });
1174
+ this._pushLog({ type: 'stdout', text: matches.join(' ') });
1061
1175
  this.render();
1062
1176
  }
1063
1177
  }
1064
1178
 
1065
1179
  submitLine() {
1180
+ if (this._readLineQueue && this._readLineQueue.length > 0) {
1181
+ const line = this.buffer;
1182
+ this.buffer = '';
1183
+ this.cursor = 0;
1184
+ this.historyIdx = -1;
1185
+ this.searchMode = false;
1186
+ this.searchQuery = '';
1187
+ this.searchMatchIdx = -1;
1188
+
1189
+ const entry = this._readLineQueue.shift();
1190
+ if (entry && typeof entry.cleanup === 'function') {
1191
+ entry.cleanup();
1192
+ }
1193
+ if (typeof entry === 'function') {
1194
+ this.updateActiveLine();
1195
+ entry(line);
1196
+ } else if (entry && typeof entry.resolve === 'function') {
1197
+ this.promptOverride = entry.prevPrompt;
1198
+ this._activateNextReadLine();
1199
+ this.updateActiveLine();
1200
+ entry.resolve(line);
1201
+ }
1202
+ return;
1203
+ }
1204
+
1205
+ if (this.isBusy) {
1206
+ return;
1207
+ }
1208
+
1066
1209
  const line = this.buffer;
1210
+ const promptSnap = this.getPrompt();
1067
1211
  this.buffer = '';
1068
1212
  this.cursor = 0;
1069
1213
  this.historyIdx = -1;
@@ -1071,22 +1215,53 @@ var CodeLabLogger = (() => {
1071
1215
  this.searchQuery = '';
1072
1216
  this.searchMatchIdx = -1;
1073
1217
 
1218
+ const echoed = this._pushLog({ type: 'system', text: `${promptSnap}${line}` });
1219
+ this._activeLineCommitted = true;
1220
+ this._cursorCol = 0;
1221
+ this._targetLineIdx = -1;
1222
+ this._needsRewrite = false;
1223
+ this._appendDomLine(echoed);
1224
+ this._activeLineEl = null;
1225
+
1074
1226
  if (line.trim()) {
1075
1227
  if (this.history[this.history.length - 1] !== line.trim()) {
1076
1228
  this.history.push(line.trim());
1229
+ const maxHist = typeof this.maxHistory === 'number' && this.maxHistory > 0 ? this.maxHistory : 1000;
1230
+ if (this.history.length > maxHist) {
1231
+ this.history.splice(0, this.history.length - maxHist);
1232
+ }
1077
1233
  }
1078
1234
  }
1079
1235
 
1080
- if (this._readLineQueue && this._readLineQueue.length > 0) {
1081
- const resolver = this._readLineQueue.shift();
1236
+ if (!this.onCommand) {
1082
1237
  this.updateActiveLine();
1083
- resolver(line);
1084
1238
  return;
1085
1239
  }
1086
1240
 
1241
+ this.isBusy = true;
1087
1242
  this.updateActiveLine();
1088
- if (this.onCommand) {
1089
- this.onCommand(line);
1243
+
1244
+ let cmdResult;
1245
+ try {
1246
+ cmdResult = this.onCommand(line);
1247
+ } catch (err) {
1248
+ this.isBusy = false;
1249
+ this.updateActiveLine();
1250
+ throw err;
1251
+ }
1252
+
1253
+ if (cmdResult && typeof cmdResult.then === 'function') {
1254
+ Promise.resolve(cmdResult)
1255
+ .catch((err) => {
1256
+ _terminalLogger.debug('Terminal onCommand promise rejected.', err);
1257
+ })
1258
+ .finally(() => {
1259
+ this.isBusy = false;
1260
+ this.updateActiveLine();
1261
+ });
1262
+ } else {
1263
+ this.isBusy = false;
1264
+ this.updateActiveLine();
1090
1265
  }
1091
1266
  }
1092
1267
 
@@ -1099,6 +1274,16 @@ var CodeLabLogger = (() => {
1099
1274
  const lineEl = this.container.querySelector('#cl-pty-active-line');
1100
1275
  if (!lineEl) return;
1101
1276
 
1277
+ if (this.isCommandRunning()) {
1278
+ if (typeof lineEl.setAttribute === 'function') lineEl.setAttribute('data-busy', 'true');
1279
+ if (lineEl.style) lineEl.style.display = 'none';
1280
+ lineEl.innerHTML = `<span class="codelab-pty__prompt"></span><span class="codelab-pty__before"></span><span class="codelab-pty__cursor"></span><span class="codelab-pty__after"></span>`;
1281
+ return;
1282
+ }
1283
+
1284
+ if (typeof lineEl.removeAttribute === 'function') lineEl.removeAttribute('data-busy');
1285
+ if (lineEl.style) lineEl.style.display = '';
1286
+
1102
1287
  const prompt = this.searchMode
1103
1288
  ? `(reverse-i-search)\`${this.searchQuery}\`: `
1104
1289
  : this.getPrompt();
@@ -1119,21 +1304,24 @@ var CodeLabLogger = (() => {
1119
1304
  );
1120
1305
 
1121
1306
  const logsHtml = this.logs
1122
- .map(item => `<div class="codelab-log-line ${escapeHtml(item.type || '')}">${ansiToHtml(item.text)}</div>`)
1307
+ .map(item => `<div class="codelab-log-line ${sanitizeLogType(item.type)}">${ansiToHtml(item.text)}</div>`)
1123
1308
  .join('');
1124
1309
 
1125
- const prompt = this.searchMode
1126
- ? `(reverse-i-search)\`${this.searchQuery}\`: `
1127
- : this.getPrompt();
1128
- const before = this.buffer.slice(0, this.cursor);
1129
- const cursorChar = this.cursor < this.buffer.length ? this.buffer[this.cursor] : ' ';
1130
- const after = this.cursor < this.buffer.length ? this.buffer.slice(this.cursor + 1) : '';
1310
+ const busy = this.isCommandRunning();
1311
+ const prompt = busy
1312
+ ? ''
1313
+ : (this.searchMode ? `(reverse-i-search)\`${this.searchQuery}\`: ` : this.getPrompt());
1314
+ const before = busy ? '' : this.buffer.slice(0, this.cursor);
1315
+ const cursorChar = busy ? '' : (this.cursor < this.buffer.length ? this.buffer[this.cursor] : ' ');
1316
+ const after = busy ? '' : (this.cursor < this.buffer.length ? this.buffer.slice(this.cursor + 1) : '');
1317
+ const busyAttr = busy ? ' data-busy="true" style="display:none;"' : '';
1318
+ const cursorClass = busy ? 'codelab-pty__cursor' : 'codelab-pty__cursor blink';
1131
1319
 
1132
1320
  this.container.innerHTML = `
1133
1321
  <div class="codelab-terminal" id="cl-terminal-surface" tabindex="0">
1134
1322
  <div class="codelab-terminal__log" id="cl-terminal-log">${logsHtml}</div>
1135
- <div class="codelab-pty__active-line" id="cl-pty-active-line">
1136
- <span class="codelab-pty__prompt">${escapeHtml(prompt)}</span><span class="codelab-pty__before">${escapeHtml(before)}</span><span class="codelab-pty__cursor blink">${escapeHtml(cursorChar)}</span><span class="codelab-pty__after">${escapeHtml(after)}</span>
1323
+ <div class="codelab-pty__active-line" id="cl-pty-active-line"${busyAttr}>
1324
+ <span class="codelab-pty__prompt">${escapeHtml(prompt)}</span><span class="codelab-pty__before">${escapeHtml(before)}</span><span class="${cursorClass}">${escapeHtml(cursorChar)}</span><span class="codelab-pty__after">${escapeHtml(after)}</span>
1137
1325
  </div>
1138
1326
  <form class="codelab-repl" id="cl-repl-form" style="position:absolute;opacity:0;pointer-events:none;height:0;overflow:hidden;">
1139
1327
  <input type="text" class="codelab-repl__input" id="cl-repl-input" autocomplete="off" spellcheck="false" aria-label="Terminal command input" value="${escapeHtml(this.buffer)}">