@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
@@ -0,0 +1,183 @@
1
+ import {
2
+ CodeLabError,
3
+ createServiceId,
4
+ Emitter,
5
+ type Event,
6
+ type IDisposable
7
+ } from '@code-lab/core';
8
+
9
+ export interface AnsiSegment {
10
+ readonly text: string;
11
+ readonly fg?: string;
12
+ readonly bold?: boolean;
13
+ }
14
+
15
+ const SGR_COLORS: Readonly<Record<number, string>> = {
16
+ 30: '#525252',
17
+ 31: '#ef4444',
18
+ 32: '#22c55e',
19
+ 33: '#eab308',
20
+ 34: '#3b82f6',
21
+ 35: '#a855f7',
22
+ 36: '#06b6d4',
23
+ 37: '#e5e5e5',
24
+ 90: '#737373',
25
+ 91: '#f87171',
26
+ 92: '#4ade80',
27
+ 93: '#facc15',
28
+ 94: '#60a5fa',
29
+ 95: '#c084fc',
30
+ 96: '#22d3ee',
31
+ 97: '#ffffff'
32
+ };
33
+
34
+ export function parseAnsiSegments(input: string): AnsiSegment[] {
35
+ const segments: AnsiSegment[] = [];
36
+ // eslint-disable-next-line no-control-regex
37
+ const sgrRegex = /\x1b\[([0-9;]*)m/g;
38
+ let lastIdx = 0;
39
+ let fg: string | undefined;
40
+ let bold = false;
41
+ let match: RegExpExecArray | null;
42
+
43
+ while ((match = sgrRegex.exec(input)) !== null) {
44
+ if (match.index > lastIdx) {
45
+ segments.push({
46
+ text: input.slice(lastIdx, match.index),
47
+ ...(fg ? { fg } : {}),
48
+ ...(bold ? { bold: true } : {})
49
+ });
50
+ }
51
+ const codes = match[1] ? match[1].split(';').map((n) => Number(n)) : [0];
52
+ for (const code of codes) {
53
+ if (code === 0) {
54
+ fg = undefined;
55
+ bold = false;
56
+ } else if (code === 1) {
57
+ bold = true;
58
+ } else if (code === 22) {
59
+ bold = false;
60
+ } else if (code === 39) {
61
+ fg = undefined;
62
+ } else if (SGR_COLORS[code]) {
63
+ fg = SGR_COLORS[code];
64
+ }
65
+ }
66
+ lastIdx = sgrRegex.lastIndex;
67
+ }
68
+
69
+ if (lastIdx < input.length) {
70
+ segments.push({
71
+ text: input.slice(lastIdx),
72
+ ...(fg ? { fg } : {}),
73
+ ...(bold ? { bold: true } : {})
74
+ });
75
+ }
76
+ return segments;
77
+ }
78
+
79
+ export interface TerminalSession {
80
+ readonly id: string;
81
+ readonly title: string;
82
+ readonly cwd: string;
83
+ readonly lines: readonly string[];
84
+ write(chunk: string): void;
85
+ clear(): void;
86
+ }
87
+
88
+ export interface ITerminalService extends IDisposable {
89
+ readonly activeSessionId: string | undefined;
90
+ readonly onDidWrite: Event<{ sessionId: string; chunk: string }>;
91
+ readonly onDidChangeSessions: Event<void>;
92
+ createSession(options?: { title?: string; cwd?: string; maxScrollback?: number }): TerminalSession;
93
+ getSessions(): TerminalSession[];
94
+ setActiveSession(id: string): void;
95
+ closeSession(id: string): void;
96
+ }
97
+
98
+ export const ITerminalServiceId = createServiceId<ITerminalService>('code-lab.terminal');
99
+
100
+ export class TerminalService implements ITerminalService {
101
+ private readonly sessions = new Map<string, TerminalSession & { _setLines: (l: string[]) => void }>();
102
+ private currentSessionId: string | undefined;
103
+ private seq = 0;
104
+ private readonly writeEmitter = new Emitter<{ sessionId: string; chunk: string }>({ name: 'terminal.write' });
105
+ private readonly sessionsEmitter = new Emitter<void>({ name: 'terminal.sessions' });
106
+
107
+ public get activeSessionId(): string | undefined {
108
+ return this.currentSessionId;
109
+ }
110
+
111
+ public get onDidWrite(): Event<{ sessionId: string; chunk: string }> {
112
+ return this.writeEmitter.event;
113
+ }
114
+
115
+ public get onDidChangeSessions(): Event<void> {
116
+ return this.sessionsEmitter.event;
117
+ }
118
+
119
+ public createSession(
120
+ options: { title?: string; cwd?: string; maxScrollback?: number } = {}
121
+ ): TerminalSession {
122
+ const id = `term-${++this.seq}`;
123
+ const title = options.title ?? `zsh ${this.seq}`;
124
+ const cwd = options.cwd ?? '/workspace';
125
+ const maxScrollback = Math.max(50, options.maxScrollback ?? 1000);
126
+ let buffer: string[] = [];
127
+
128
+ const session: TerminalSession & { _setLines: (l: string[]) => void } = {
129
+ id,
130
+ title,
131
+ cwd,
132
+ get lines(): readonly string[] {
133
+ return buffer;
134
+ },
135
+ write: (chunk: string): void => {
136
+ const incoming = chunk.split('\n');
137
+ buffer.push(...incoming);
138
+ if (buffer.length > maxScrollback) {
139
+ buffer = buffer.slice(buffer.length - maxScrollback);
140
+ }
141
+ this.writeEmitter.fire({ sessionId: id, chunk });
142
+ },
143
+ clear: (): void => {
144
+ buffer = [];
145
+ },
146
+ _setLines: (l: string[]): void => {
147
+ buffer = l;
148
+ }
149
+ };
150
+
151
+ this.sessions.set(id, session);
152
+ this.currentSessionId = id;
153
+ this.sessionsEmitter.fire();
154
+ return session;
155
+ }
156
+
157
+ public getSessions(): TerminalSession[] {
158
+ return Array.from(this.sessions.values());
159
+ }
160
+
161
+ public setActiveSession(id: string): void {
162
+ if (!this.sessions.has(id)) {
163
+ throw new CodeLabError('ERR_INVALID_ARGUMENT', `Terminal session "${id}" does not exist`);
164
+ }
165
+ this.currentSessionId = id;
166
+ this.sessionsEmitter.fire();
167
+ }
168
+
169
+ public closeSession(id: string): void {
170
+ if (!this.sessions.delete(id)) return;
171
+ if (this.currentSessionId === id) {
172
+ this.currentSessionId = this.sessions.keys().next().value;
173
+ }
174
+ this.sessionsEmitter.fire();
175
+ }
176
+
177
+ public dispose(): void {
178
+ this.sessions.clear();
179
+ this.currentSessionId = undefined;
180
+ this.writeEmitter.dispose();
181
+ this.sessionsEmitter.dispose();
182
+ }
183
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022", "DOM"],
7
+ "strict": true,
8
+ "noImplicitAny": true,
9
+ "strictNullChecks": true,
10
+ "noUnusedLocals": true,
11
+ "noUnusedParameters": true,
12
+ "noImplicitReturns": true,
13
+ "noFallthroughCasesInSwitch": true,
14
+ "noEmit": true,
15
+ "skipLibCheck": true,
16
+ "forceConsistentCasingInFileNames": true,
17
+ "paths": {
18
+ "@code-lab/core": ["../core/src/index.ts"]
19
+ }
20
+ },
21
+ "include": ["src/**/*.ts"]
22
+ }
@@ -0,0 +1,8 @@
1
+ # `@code-lab/ui`
2
+
3
+ Layer 3 (`workbench`) UI controllers, theming, plugin contribution points, and developer observability for **CodeLab**:
4
+
5
+ - `ThemeService` — built-in `dark`, `light`, and `high-contrast` themes plus JSON custom theme loader (`parseCustomTheme`).
6
+ - `SettingsDialogController` — searchable modal `<dialog closedby="any">` Settings UI with category filters, Reset to Default, Export, and Open `.codelab/settings.json`.
7
+ - `PluginRegistry` — VS Code-inspired declarative contribution points (`commands`, `settings`, `keybindings`, `themes`, `panels`, `languages`) with lazy activation events and clean `IDisposable` deactivation.
8
+ - `renderObservabilityPanelHtml` & `WorkbenchErrorBoundary` — Dev Observability Inspector and user-visible error boundary.
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@code-lab/ui",
3
+ "version": "0.4.0",
4
+ "description": "Workbench UI services and components for CodeLab: ThemeService (dark/light/high-contrast/custom), Searchable Settings Dialog, Quick Open, PluginRegistry, ErrorBoundary, and Dev Observability Inspector.",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "types": "./src/index.ts",
8
+ "exports": {
9
+ ".": "./src/index.ts"
10
+ },
11
+ "dependencies": {
12
+ "@code-lab/core": "workspace:*",
13
+ "@code-lab/settings": "workspace:*",
14
+ "@code-lab/commands": "workspace:*"
15
+ },
16
+ "sideEffects": false,
17
+ "license": "MIT"
18
+ }
@@ -0,0 +1,36 @@
1
+ export {
2
+ type ThemeKind,
3
+ type ThemeDefinition,
4
+ type IThemeService,
5
+ DARK_THEME,
6
+ LIGHT_THEME,
7
+ HIGH_CONTRAST_THEME,
8
+ IThemeServiceId,
9
+ parseCustomTheme,
10
+ ThemeService
11
+ } from './themes';
12
+
13
+ export {
14
+ type PanelContribution,
15
+ type LanguageContribution,
16
+ type PluginContributions,
17
+ type PluginActivationContext,
18
+ type CodeLabPluginManifest,
19
+ type RegisteredPluginInfo,
20
+ type IPluginRegistry,
21
+ IPluginRegistryId,
22
+ PluginRegistry
23
+ } from './plugin-registry';
24
+
25
+ export {
26
+ type SettingsDialogOptions,
27
+ SettingsDialogController
28
+ } from './settings-dialog';
29
+
30
+ export {
31
+ type ObservabilitySnapshotInput,
32
+ scoreFuzzyFileMatch,
33
+ rankWorkspaceFiles,
34
+ renderObservabilityPanelHtml,
35
+ WorkbenchErrorBoundary
36
+ } from './observability';
@@ -0,0 +1,175 @@
1
+ import type { EventTraceRecord, ILogger, IServiceContainer, LogEntry } from '@code-lab/core';
2
+ import type { IConfigurationService } from '@code-lab/settings';
3
+ import type { IPluginRegistry } from './plugin-registry';
4
+
5
+ function escapeHtml(raw: string): string {
6
+ return raw
7
+ .replace(/&/g, '&amp;')
8
+ .replace(/</g, '&lt;')
9
+ .replace(/>/g, '&gt;')
10
+ .replace(/"/g, '&quot;');
11
+ }
12
+
13
+ export function scoreFuzzyFileMatch(candidatePath: string, query: string): number {
14
+ if (!query) return 1;
15
+ const cleanQuery = query.toLowerCase().replace(/\s+/g, '');
16
+ const lowerPath = candidatePath.toLowerCase();
17
+ if (lowerPath === cleanQuery) return 1000;
18
+ const baseIdx = lowerPath.lastIndexOf('/');
19
+ const baseName = baseIdx === -1 ? lowerPath : lowerPath.slice(baseIdx + 1);
20
+ if (baseName.startsWith(cleanQuery)) return 500 - baseName.length;
21
+ if (lowerPath.includes(cleanQuery)) return 300 - lowerPath.length;
22
+
23
+ let qIdx = 0;
24
+ let score = 0;
25
+ let streak = 0;
26
+ for (let i = 0; i < lowerPath.length && qIdx < cleanQuery.length; i++) {
27
+ if (lowerPath[i] === cleanQuery[qIdx]) {
28
+ qIdx++;
29
+ streak++;
30
+ score += 10 + streak * 4;
31
+ } else {
32
+ streak = 0;
33
+ }
34
+ }
35
+ return qIdx === cleanQuery.length ? score : -1;
36
+ }
37
+
38
+ export function rankWorkspaceFiles(
39
+ filePaths: readonly string[],
40
+ query: string,
41
+ excludePatterns: readonly string[] = []
42
+ ): string[] {
43
+ const filtered = filePaths.filter((p) => {
44
+ for (const ex of excludePatterns) {
45
+ const token = ex.replace(/\*\*/g, '').replace(/\*/g, '').replace(/^\/+|\/+$/g, '');
46
+ if (token && p.includes(token)) return false;
47
+ }
48
+ return true;
49
+ });
50
+ const scored: Array<{ path: string; score: number }> = [];
51
+ for (const p of filtered) {
52
+ const score = scoreFuzzyFileMatch(p, query);
53
+ if (score >= 0) scored.push({ path: p, score });
54
+ }
55
+ scored.sort((a, b) => b.score - a.score || a.path.localeCompare(b.path));
56
+ return scored.map((s) => s.path);
57
+ }
58
+
59
+ export interface ObservabilitySnapshotInput {
60
+ readonly container: IServiceContainer;
61
+ readonly configuration: IConfigurationService;
62
+ readonly plugins: IPluginRegistry;
63
+ readonly logger: ILogger;
64
+ readonly recentEvents: readonly EventTraceRecord[];
65
+ readonly workerStatus?: string;
66
+ }
67
+
68
+ export function renderObservabilityPanelHtml(input: ObservabilitySnapshotInput): string {
69
+ const serviceIds = input.container.listRegisteredIds();
70
+ const plugins = input.plugins.getPlugins();
71
+ const logs: readonly LogEntry[] = input.logger.getRecentEntries().slice(-15).reverse();
72
+ const events = input.recentEvents.slice(-15).reverse();
73
+ const configDiags = input.configuration.getDiagnostics();
74
+
75
+ return (
76
+ `<div class="cl-observability-panel" style="padding:10px 14px;font-size:12px;display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:12px;">` +
77
+ `<section style="border:1px solid var(--cl-border,#262626);border-radius:6px;padding:8px 10px;">` +
78
+ `<strong>Services & Runtime (${serviceIds.length})</strong>` +
79
+ `<div style="margin-top:4px;color:var(--cl-muted,#8e8e93);">Worker Host: <code>${escapeHtml(input.workerStatus ?? 'ready')}</code></div>` +
80
+ `<ul style="margin:6px 0 0;padding-left:16px;">` +
81
+ serviceIds.map((id) => `<li><code>${escapeHtml(id)}</code></li>`).join('') +
82
+ `</ul>` +
83
+ `</section>` +
84
+ `<section style="border:1px solid var(--cl-border,#262626);border-radius:6px;padding:8px 10px;">` +
85
+ `<strong>Plugins (${plugins.length}) & Config Diagnostics (${configDiags.length})</strong>` +
86
+ `<ul style="margin:6px 0 0;padding-left:16px;">` +
87
+ (plugins.length > 0
88
+ ? plugins
89
+ .map(
90
+ (p) =>
91
+ `<li><code>${escapeHtml(p.manifest.id)}</code> v${escapeHtml(p.manifest.version)} — ${p.active ? 'active' : 'lazy'}</li>`
92
+ )
93
+ .join('')
94
+ : `<li>No external plugins registered</li>`) +
95
+ `</ul>` +
96
+ (configDiags.length > 0
97
+ ? `<div style="margin-top:6px;color:#f59e0b;">` +
98
+ configDiags.map((d) => `<div>⚠ ${escapeHtml(d.message)}</div>`).join('') +
99
+ `</div>`
100
+ : '') +
101
+ `</section>` +
102
+ `<section style="border:1px solid var(--cl-border,#262626);border-radius:6px;padding:8px 10px;">` +
103
+ `<strong>Recent Event Bus (${events.length})</strong>` +
104
+ `<ul style="margin:6px 0 0;padding-left:16px;max-height:130px;overflow-y:auto;">` +
105
+ (events.length > 0
106
+ ? events
107
+ .map(
108
+ (e) =>
109
+ `<li><code>${escapeHtml(e.channel)}</code> (${e.listenerCount}) — ${escapeHtml(e.payloadSummary)}</li>`
110
+ )
111
+ .join('')
112
+ : `<li>No events recorded yet</li>`) +
113
+ `</ul>` +
114
+ `</section>` +
115
+ `<section style="border:1px solid var(--cl-border,#262626);border-radius:6px;padding:8px 10px;">` +
116
+ `<strong>Recent Logs (${logs.length})</strong>` +
117
+ `<ul style="margin:6px 0 0;padding-left:16px;max-height:130px;overflow-y:auto;">` +
118
+ (logs.length > 0
119
+ ? logs
120
+ .map(
121
+ (l) =>
122
+ `<li><strong>[${escapeHtml(l.level)}]</strong> <code>${escapeHtml(l.scope)}</code>: ${escapeHtml(l.message)}</li>`
123
+ )
124
+ .join('')
125
+ : `<li>No log entries</li>`) +
126
+ `</ul>` +
127
+ `</section>` +
128
+ `</div>`
129
+ );
130
+ }
131
+
132
+ export class WorkbenchErrorBoundary {
133
+ private readonly host: HTMLElement;
134
+ private readonly logger: ILogger;
135
+ private bannerEl: HTMLElement | null = null;
136
+
137
+ public constructor(host: HTMLElement, logger: ILogger) {
138
+ this.host = host;
139
+ this.logger = logger.child('error-boundary');
140
+ }
141
+
142
+ public capture(error: unknown, contextLabel = 'Workbench operation'): void {
143
+ const msg = error instanceof Error ? error.message : String(error);
144
+ this.logger.error(`${contextLabel} failed: ${msg}`, error);
145
+ const doc = this.host.ownerDocument ?? document;
146
+ if (!this.bannerEl) {
147
+ this.bannerEl = doc.createElement('div');
148
+ this.bannerEl.className = 'cl-error-boundary-banner';
149
+ this.bannerEl.setAttribute('role', 'alert');
150
+ this.bannerEl.style.cssText =
151
+ 'display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 12px;background:rgba(239,68,68,0.15);border-bottom:1px solid #ef4444;color:var(--cl-fg,#f5f5f5);font-size:12px;';
152
+ if (typeof this.host.prepend === 'function') {
153
+ this.host.prepend(this.bannerEl);
154
+ } else {
155
+ this.host.appendChild(this.bannerEl);
156
+ }
157
+ }
158
+ this.bannerEl.innerHTML =
159
+ `<span><strong>${escapeHtml(contextLabel)}:</strong> ${escapeHtml(msg)}</span>` +
160
+ `<button type="button" class="codelab-btn" data-dismiss-error="1" style="padding:2px 8px;font-size:11px;">Dismiss</button>`;
161
+ const dismissBtn = this.bannerEl.querySelector('[data-dismiss-error]');
162
+ dismissBtn?.addEventListener(
163
+ 'click',
164
+ () => {
165
+ this.clear();
166
+ },
167
+ { once: true }
168
+ );
169
+ }
170
+
171
+ public clear(): void {
172
+ this.bannerEl?.remove();
173
+ this.bannerEl = null;
174
+ }
175
+ }