@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,112 @@
1
+ /**
2
+ * @code-lab/core — Deterministic lifecycle and disposable management.
3
+ * Zero DOM dependencies (Layer 0).
4
+ */
5
+
6
+ export interface IDisposable {
7
+ dispose(): void;
8
+ }
9
+
10
+ export function isDisposable(value: unknown): value is IDisposable {
11
+ return (
12
+ typeof value === 'object' &&
13
+ value !== null &&
14
+ typeof (value as IDisposable).dispose === 'function'
15
+ );
16
+ }
17
+
18
+ export function toDisposable(fn: () => void): IDisposable {
19
+ let disposed = false;
20
+ return {
21
+ dispose(): void {
22
+ if (disposed) return;
23
+ disposed = true;
24
+ fn();
25
+ }
26
+ };
27
+ }
28
+
29
+ export class DisposableStore implements IDisposable {
30
+ private readonly items = new Set<IDisposable>();
31
+ private disposed = false;
32
+
33
+ public get isDisposed(): boolean {
34
+ return this.disposed;
35
+ }
36
+
37
+ public get size(): number {
38
+ return this.items.size;
39
+ }
40
+
41
+ public add<T extends IDisposable>(item: T): T {
42
+ if (this.disposed) {
43
+ item.dispose();
44
+ return item;
45
+ }
46
+ this.items.add(item);
47
+ return item;
48
+ }
49
+
50
+ public addFn(cleanup: () => void): IDisposable {
51
+ return this.add(toDisposable(cleanup));
52
+ }
53
+
54
+ public clear(): void {
55
+ const snapshot = Array.from(this.items);
56
+ this.items.clear();
57
+ const errors: unknown[] = [];
58
+ for (let i = snapshot.length - 1; i >= 0; i--) {
59
+ try {
60
+ snapshot[i].dispose();
61
+ } catch (err) {
62
+ errors.push(err);
63
+ }
64
+ }
65
+ if (errors.length === 1) {
66
+ throw errors[0];
67
+ }
68
+ if (errors.length > 1) {
69
+ throw new AggregateError(errors, 'Multiple errors occurred while clearing DisposableStore');
70
+ }
71
+ }
72
+
73
+ public dispose(): void {
74
+ if (this.disposed) return;
75
+ this.disposed = true;
76
+ this.clear();
77
+ }
78
+ }
79
+
80
+ export class MutableDisposable<T extends IDisposable> implements IDisposable {
81
+ private current: T | undefined;
82
+ private disposed = false;
83
+
84
+ public get value(): T | undefined {
85
+ return this.current;
86
+ }
87
+
88
+ public set value(next: T | undefined) {
89
+ if (this.disposed) {
90
+ if (next) next.dispose();
91
+ return;
92
+ }
93
+ if (this.current === next) return;
94
+ if (this.current) {
95
+ this.current.dispose();
96
+ }
97
+ this.current = next;
98
+ }
99
+
100
+ public clear(): void {
101
+ if (this.current) {
102
+ this.current.dispose();
103
+ this.current = undefined;
104
+ }
105
+ }
106
+
107
+ public dispose(): void {
108
+ if (this.disposed) return;
109
+ this.disposed = true;
110
+ this.clear();
111
+ }
112
+ }
@@ -0,0 +1,205 @@
1
+ /**
2
+ * @code-lab/core — Typed error hierarchy & central ring-buffered Logger.
3
+ */
4
+
5
+ import { type Event, Emitter } from './events';
6
+
7
+ export type CodeLabErrorCode =
8
+ | 'ERR_INVALID_ARGUMENT'
9
+ | 'ERR_DISPOSED'
10
+ | 'ERR_DI_MISSING'
11
+ | 'ERR_DI_CYCLE'
12
+ | 'ERR_FS_NOT_FOUND'
13
+ | 'ERR_FS_EXISTS'
14
+ | 'ERR_FS_IS_DIR'
15
+ | 'ERR_FS_NOT_DIR'
16
+ | 'ERR_FS_QUOTA'
17
+ | 'ERR_CONFIG_PARSE'
18
+ | 'ERR_CONFIG_SCHEMA'
19
+ | 'ERR_COMMAND_NOT_FOUND'
20
+ | 'ERR_RUNTIME_TIMEOUT'
21
+ | 'ERR_RUNTIME_CRASH'
22
+ | 'ERR_PLUGIN_INVALID'
23
+ | 'ERR_SECURITY_POLICY';
24
+
25
+ export interface CodeLabErrorOptions {
26
+ readonly cause?: unknown;
27
+ readonly context?: Readonly<Record<string, unknown>>;
28
+ readonly recoverable?: boolean;
29
+ }
30
+
31
+ export class CodeLabError extends Error {
32
+ public readonly code: CodeLabErrorCode;
33
+ public readonly context: Readonly<Record<string, unknown>>;
34
+ public readonly recoverable: boolean;
35
+
36
+ public constructor(code: CodeLabErrorCode, message: string, options: CodeLabErrorOptions = {}) {
37
+ super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
38
+ this.name = 'CodeLabError';
39
+ this.code = code;
40
+ this.context = Object.freeze({ ...(options.context ?? {}) });
41
+ this.recoverable = options.recoverable ?? true;
42
+ }
43
+ }
44
+
45
+ export function isCodeLabError(value: unknown): value is CodeLabError {
46
+ return value instanceof CodeLabError || (
47
+ typeof value === 'object' &&
48
+ value !== null &&
49
+ (value as { name?: unknown }).name === 'CodeLabError' &&
50
+ typeof (value as { code?: unknown }).code === 'string'
51
+ );
52
+ }
53
+
54
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
55
+
56
+ const LEVEL_RANK: Readonly<Record<LogLevel, number>> = {
57
+ debug: 10,
58
+ info: 20,
59
+ warn: 30,
60
+ error: 40,
61
+ silent: 100
62
+ };
63
+
64
+ export interface LogEntry {
65
+ readonly timestamp: number;
66
+ readonly level: Exclude<LogLevel, 'silent'>;
67
+ readonly scope: string;
68
+ readonly message: string;
69
+ readonly data?: unknown;
70
+ }
71
+
72
+ export interface ILogger {
73
+ readonly scope: string;
74
+ readonly onDidLog: Event<LogEntry>;
75
+ debug(message: string, data?: unknown): void;
76
+ info(message: string, data?: unknown): void;
77
+ warn(message: string, data?: unknown): void;
78
+ error(message: string, data?: unknown): void;
79
+ child(subScope: string): ILogger;
80
+ getRecentEntries(): readonly LogEntry[];
81
+ setLevel(level: LogLevel): void;
82
+ getLevel(): LogLevel;
83
+ }
84
+
85
+ export interface LoggerOptions {
86
+ readonly scope?: string;
87
+ readonly level?: LogLevel;
88
+ readonly maxEntries?: number;
89
+ readonly sink?: (entry: LogEntry) => void;
90
+ }
91
+
92
+ export class Logger implements ILogger {
93
+ public readonly scope: string;
94
+ private level: LogLevel;
95
+ private readonly maxEntries: number;
96
+ private readonly buffer: LogEntry[];
97
+ private readonly emitter: Emitter<LogEntry>;
98
+ private readonly sink?: (entry: LogEntry) => void;
99
+
100
+ public constructor(
101
+ options: LoggerOptions = {},
102
+ sharedState?: {
103
+ buffer: LogEntry[];
104
+ emitter: Emitter<LogEntry>;
105
+ getLevel: () => LogLevel;
106
+ setLevel: (l: LogLevel) => void;
107
+ maxEntries: number;
108
+ sink?: (entry: LogEntry) => void;
109
+ }
110
+ ) {
111
+ this.scope = options.scope ?? 'codelab';
112
+ this.level = options.level ?? 'warn';
113
+ this.maxEntries = sharedState ? sharedState.maxEntries : (options.maxEntries ?? 200);
114
+ this.buffer = sharedState ? sharedState.buffer : [];
115
+ this.emitter = sharedState ? sharedState.emitter : new Emitter<LogEntry>({ name: 'logger' });
116
+ this.sink = sharedState ? sharedState.sink : options.sink;
117
+ if (sharedState) {
118
+ this.getLevel = sharedState.getLevel;
119
+ this.setLevel = sharedState.setLevel;
120
+ }
121
+ }
122
+
123
+ public get onDidLog(): Event<LogEntry> {
124
+ return this.emitter.event;
125
+ }
126
+
127
+ public getLevel(): LogLevel {
128
+ return this.level;
129
+ }
130
+
131
+ public setLevel(level: LogLevel): void {
132
+ this.level = level;
133
+ }
134
+
135
+ public getRecentEntries(): readonly LogEntry[] {
136
+ return this.buffer.slice();
137
+ }
138
+
139
+ public debug(message: string, data?: unknown): void {
140
+ this.write('debug', message, data);
141
+ }
142
+
143
+ public info(message: string, data?: unknown): void {
144
+ this.write('info', message, data);
145
+ }
146
+
147
+ public warn(message: string, data?: unknown): void {
148
+ this.write('warn', message, data);
149
+ }
150
+
151
+ public error(message: string, data?: unknown): void {
152
+ this.write('error', message, data);
153
+ }
154
+
155
+ public child(subScope: string): ILogger {
156
+ return new Logger(
157
+ { scope: `${this.scope}:${subScope}` },
158
+ {
159
+ buffer: this.buffer,
160
+ emitter: this.emitter,
161
+ getLevel: () => this.getLevel(),
162
+ setLevel: (l) => this.setLevel(l),
163
+ maxEntries: this.maxEntries,
164
+ sink: this.sink
165
+ }
166
+ );
167
+ }
168
+
169
+ private write(level: Exclude<LogLevel, 'silent'>, message: string, data?: unknown): void {
170
+ const entry: LogEntry = {
171
+ timestamp: Date.now(),
172
+ level,
173
+ scope: this.scope,
174
+ message,
175
+ ...(data !== undefined ? { data } : {})
176
+ };
177
+ this.buffer.push(entry);
178
+ if (this.buffer.length > this.maxEntries) {
179
+ this.buffer.splice(0, this.buffer.length - this.maxEntries);
180
+ }
181
+ this.emitter.fire(entry);
182
+ if (LEVEL_RANK[level] < LEVEL_RANK[this.getLevel()]) {
183
+ return;
184
+ }
185
+ if (this.sink) {
186
+ this.sink(entry);
187
+ return;
188
+ }
189
+ const formatted = `[CodeLab][${this.scope}] ${message}`;
190
+ if (level === 'error') {
191
+ if (data !== undefined) console.error(formatted, data);
192
+ else console.error(formatted);
193
+ } else if (level === 'warn') {
194
+ if (data !== undefined) console.warn(formatted, data);
195
+ else console.warn(formatted);
196
+ } else if (level === 'info') {
197
+ if (data !== undefined) console.info(formatted, data);
198
+ else console.info(formatted);
199
+ } else if (data !== undefined) {
200
+ console.debug(formatted, data);
201
+ } else {
202
+ console.debug(formatted);
203
+ }
204
+ }
205
+ }
@@ -0,0 +1,157 @@
1
+ /**
2
+ * @code-lab/core — Typed Event<T> & Emitter<T> bus (VS Code / Lumino pattern).
3
+ * Every subscription returns an IDisposable so listeners never leak.
4
+ */
5
+
6
+ import { type IDisposable, toDisposable } from './disposable';
7
+
8
+ export type EventListener<T> = (event: T) => void;
9
+
10
+ export type Event<T> = (listener: EventListener<T>) => IDisposable;
11
+
12
+ export interface EventTraceRecord {
13
+ readonly channel: string;
14
+ readonly timestamp: number;
15
+ readonly listenerCount: number;
16
+ readonly payloadSummary: string;
17
+ }
18
+
19
+ export type EventMonitorHook = (record: EventTraceRecord) => void;
20
+
21
+ let globalEventMonitor: EventMonitorHook | null = null;
22
+
23
+ export function setGlobalEventMonitor(hook: EventMonitorHook | null): IDisposable {
24
+ globalEventMonitor = hook;
25
+ return toDisposable(() => {
26
+ if (globalEventMonitor === hook) {
27
+ globalEventMonitor = null;
28
+ }
29
+ });
30
+ }
31
+
32
+ function summarizePayload(payload: unknown): string {
33
+ if (payload === undefined) return 'void';
34
+ if (payload === null) return 'null';
35
+ if (typeof payload === 'string') {
36
+ return payload.length > 80 ? `${payload.slice(0, 77)}...` : payload;
37
+ }
38
+ if (typeof payload === 'number' || typeof payload === 'boolean') {
39
+ return String(payload);
40
+ }
41
+ try {
42
+ const raw = JSON.stringify(payload);
43
+ if (!raw) return typeof payload;
44
+ return raw.length > 100 ? `${raw.slice(0, 97)}...` : raw;
45
+ } catch {
46
+ return Object.prototype.toString.call(payload);
47
+ }
48
+ }
49
+
50
+ export interface EmitterOptions {
51
+ readonly name?: string;
52
+ readonly leakWarningThreshold?: number;
53
+ readonly onListenerError?: (err: unknown) => void;
54
+ }
55
+
56
+ export class Emitter<T> implements IDisposable {
57
+ private readonly listeners = new Set<EventListener<T>>();
58
+ private readonly channelName: string;
59
+ private readonly leakThreshold: number;
60
+ private readonly onListenerError?: (err: unknown) => void;
61
+ private disposed = false;
62
+ private cachedEvent: Event<T> | null = null;
63
+
64
+ public constructor(options: EmitterOptions = {}) {
65
+ this.channelName = options.name ?? 'anonymous';
66
+ this.leakThreshold = options.leakWarningThreshold ?? 250;
67
+ this.onListenerError = options.onListenerError;
68
+ }
69
+
70
+ public get listenerCount(): number {
71
+ return this.listeners.size;
72
+ }
73
+
74
+ public get event(): Event<T> {
75
+ if (!this.cachedEvent) {
76
+ this.cachedEvent = (listener: EventListener<T>): IDisposable => {
77
+ if (this.disposed) {
78
+ return toDisposable(() => {});
79
+ }
80
+ this.listeners.add(listener);
81
+ if (this.leakThreshold > 0 && this.listeners.size > this.leakThreshold) {
82
+ console.warn(
83
+ `[CodeLab][Emitter:${this.channelName}] Listener count (${this.listeners.size}) exceeded threshold (${this.leakThreshold}). Check for missing dispose() calls.`
84
+ );
85
+ }
86
+ return toDisposable(() => {
87
+ this.listeners.delete(listener);
88
+ });
89
+ };
90
+ }
91
+ return this.cachedEvent;
92
+ }
93
+
94
+ public fire(payload: T): void {
95
+ if (this.disposed) return;
96
+ if (globalEventMonitor) {
97
+ globalEventMonitor({
98
+ channel: this.channelName,
99
+ timestamp: Date.now(),
100
+ listenerCount: this.listeners.size,
101
+ payloadSummary: summarizePayload(payload)
102
+ });
103
+ }
104
+ if (this.listeners.size === 0) return;
105
+ const snapshot = Array.from(this.listeners);
106
+ for (const listener of snapshot) {
107
+ try {
108
+ listener(payload);
109
+ } catch (err) {
110
+ if (this.onListenerError) {
111
+ this.onListenerError(err);
112
+ } else {
113
+ throw err;
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ public dispose(): void {
120
+ if (this.disposed) return;
121
+ this.disposed = true;
122
+ this.listeners.clear();
123
+ }
124
+ }
125
+
126
+ export namespace EventUtils {
127
+ export function once<T>(event: Event<T>): Event<T> {
128
+ return (listener: EventListener<T>): IDisposable => {
129
+ let didFire = false;
130
+ let sub: IDisposable | null = null;
131
+ sub = event((value) => {
132
+ if (didFire) return;
133
+ didFire = true;
134
+ if (sub) sub.dispose();
135
+ listener(value);
136
+ });
137
+ if (didFire) {
138
+ sub.dispose();
139
+ }
140
+ return sub;
141
+ };
142
+ }
143
+
144
+ export function filter<T>(event: Event<T>, predicate: (value: T) => boolean): Event<T> {
145
+ return (listener: EventListener<T>): IDisposable =>
146
+ event((value) => {
147
+ if (predicate(value)) listener(value);
148
+ });
149
+ }
150
+
151
+ export function map<I, O>(event: Event<I>, mapper: (value: I) => O): Event<O> {
152
+ return (listener: EventListener<O>): IDisposable =>
153
+ event((value) => {
154
+ listener(mapper(value));
155
+ });
156
+ }
157
+ }
@@ -0,0 +1,49 @@
1
+ export {
2
+ type IDisposable,
3
+ isDisposable,
4
+ toDisposable,
5
+ DisposableStore,
6
+ MutableDisposable
7
+ } from './disposable';
8
+
9
+ export {
10
+ type Event,
11
+ type EventListener,
12
+ type EventTraceRecord,
13
+ type EventMonitorHook,
14
+ type EmitterOptions,
15
+ Emitter,
16
+ EventUtils,
17
+ setGlobalEventMonitor
18
+ } from './events';
19
+
20
+ export {
21
+ type ServiceId,
22
+ type ServiceFactory,
23
+ type IServiceContainer,
24
+ createServiceId,
25
+ ServiceContainer
26
+ } from './di';
27
+
28
+ export {
29
+ type CodeLabErrorCode,
30
+ type CodeLabErrorOptions,
31
+ type LogLevel,
32
+ type LogEntry,
33
+ type ILogger,
34
+ type LoggerOptions,
35
+ CodeLabError,
36
+ isCodeLabError,
37
+ Logger
38
+ } from './errors';
39
+
40
+ export {
41
+ PosixPath,
42
+ globToRegExp,
43
+ matchesGlob
44
+ } from './path';
45
+
46
+ export {
47
+ type ContributionChangeEvent,
48
+ ContributionRegistry
49
+ } from './registry';
@@ -0,0 +1,118 @@
1
+ /**
2
+ * @code-lab/core — Pure POSIX path and glob matching utilities (zero Node/DOM deps).
3
+ */
4
+
5
+ export const PosixPath = {
6
+ isAbsolute(filePath: string): boolean {
7
+ return filePath.startsWith('/');
8
+ },
9
+
10
+ normalize(filePath: string): string {
11
+ if (!filePath) return '.';
12
+ const isAbs = filePath.startsWith('/');
13
+ const parts = filePath.split('/');
14
+ const stack: string[] = [];
15
+ for (const part of parts) {
16
+ if (!part || part === '.') continue;
17
+ if (part === '..') {
18
+ if (stack.length > 0 && stack[stack.length - 1] !== '..') {
19
+ stack.pop();
20
+ } else if (!isAbs) {
21
+ stack.push('..');
22
+ }
23
+ } else {
24
+ stack.push(part);
25
+ }
26
+ }
27
+ const joined = stack.join('/');
28
+ if (isAbs) return '/' + joined;
29
+ return joined || '.';
30
+ },
31
+
32
+ join(...segments: string[]): string {
33
+ const filtered = segments.filter((s) => s.length > 0);
34
+ if (filtered.length === 0) return '.';
35
+ return PosixPath.normalize(filtered.join('/'));
36
+ },
37
+
38
+ dirname(filePath: string): string {
39
+ const norm = PosixPath.normalize(filePath);
40
+ if (norm === '/') return '/';
41
+ const idx = norm.lastIndexOf('/');
42
+ if (idx === -1) return '.';
43
+ if (idx === 0) return '/';
44
+ return norm.slice(0, idx);
45
+ },
46
+
47
+ basename(filePath: string, suffix?: string): string {
48
+ const norm = PosixPath.normalize(filePath);
49
+ if (norm === '/') return '/';
50
+ const idx = norm.lastIndexOf('/');
51
+ const base = idx === -1 ? norm : norm.slice(idx + 1);
52
+ if (suffix && base.endsWith(suffix)) {
53
+ return base.slice(0, base.length - suffix.length);
54
+ }
55
+ return base;
56
+ },
57
+
58
+ extname(filePath: string): string {
59
+ const base = PosixPath.basename(filePath);
60
+ const idx = base.lastIndexOf('.');
61
+ if (idx <= 0) return '';
62
+ return base.slice(idx);
63
+ },
64
+
65
+ relative(from: string, to: string): string {
66
+ const a = PosixPath.normalize(from).replace(/^\/+/, '').split('/').filter(Boolean);
67
+ const b = PosixPath.normalize(to).replace(/^\/+/, '').split('/').filter(Boolean);
68
+ let common = 0;
69
+ while (common < a.length && common < b.length && a[common] === b[common]) {
70
+ common++;
71
+ }
72
+ const up = new Array<string>(a.length - common).fill('..');
73
+ const down = b.slice(common);
74
+ return [...up, ...down].join('/') || '.';
75
+ }
76
+ };
77
+
78
+ export function globToRegExp(pattern: string): RegExp {
79
+ let regex = '^';
80
+ let i = 0;
81
+ while (i < pattern.length) {
82
+ const ch = pattern[i];
83
+ if (ch === '*') {
84
+ if (pattern[i + 1] === '*') {
85
+ if (pattern[i + 2] === '/') {
86
+ regex += '(?:.*/)?';
87
+ i += 3;
88
+ continue;
89
+ }
90
+ regex += '.*';
91
+ i += 2;
92
+ continue;
93
+ }
94
+ regex += '[^/]*';
95
+ i++;
96
+ continue;
97
+ }
98
+ if (ch === '?') {
99
+ regex += '[^/]';
100
+ i++;
101
+ continue;
102
+ }
103
+ if ('\\^$.|+()[]{}'.includes(ch)) {
104
+ regex += '\\' + ch;
105
+ } else {
106
+ regex += ch;
107
+ }
108
+ i++;
109
+ }
110
+ regex += '$';
111
+ return new RegExp(regex);
112
+ }
113
+
114
+ export function matchesGlob(targetPath: string, pattern: string): boolean {
115
+ const cleanTarget = targetPath.replace(/^\/+/, '');
116
+ const cleanPattern = pattern.replace(/^\/+/, '');
117
+ return globToRegExp(cleanPattern).test(cleanTarget);
118
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @code-lab/core — Generic typed ContributionRegistry for plugins & extension points.
3
+ */
4
+
5
+ import { type IDisposable, toDisposable } from './disposable';
6
+ import { Emitter, type Event } from './events';
7
+
8
+ export interface ContributionChangeEvent<K, V> {
9
+ readonly kind: 'added' | 'removed';
10
+ readonly key: K;
11
+ readonly value: V;
12
+ }
13
+
14
+ export class ContributionRegistry<K, V> implements IDisposable {
15
+ private readonly items = new Map<K, V>();
16
+ private readonly emitter: Emitter<ContributionChangeEvent<K, V>>;
17
+
18
+ public constructor(pointName = 'contributions') {
19
+ this.emitter = new Emitter<ContributionChangeEvent<K, V>>({ name: `registry:${pointName}` });
20
+ }
21
+
22
+ public get onDidChange(): Event<ContributionChangeEvent<K, V>> {
23
+ return this.emitter.event;
24
+ }
25
+
26
+ public register(key: K, value: V): IDisposable {
27
+ this.items.set(key, value);
28
+ this.emitter.fire({ kind: 'added', key, value });
29
+ return toDisposable(() => {
30
+ if (this.items.get(key) === value) {
31
+ this.items.delete(key);
32
+ this.emitter.fire({ kind: 'removed', key, value });
33
+ }
34
+ });
35
+ }
36
+
37
+ public get(key: K): V | undefined {
38
+ return this.items.get(key);
39
+ }
40
+
41
+ public has(key: K): boolean {
42
+ return this.items.has(key);
43
+ }
44
+
45
+ public entries(): Array<[K, V]> {
46
+ return Array.from(this.items.entries());
47
+ }
48
+
49
+ public values(): V[] {
50
+ return Array.from(this.items.values());
51
+ }
52
+
53
+ public size(): number {
54
+ return this.items.size;
55
+ }
56
+
57
+ public dispose(): void {
58
+ this.items.clear();
59
+ this.emitter.dispose();
60
+ }
61
+ }