@innovatorved/code-lab 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +5 -5
  4. package/dist/code-lab-sql.esm.js +2 -2
  5. package/dist/code-lab-sql.umd.js +3 -3
  6. package/dist/code-lab.css +1 -1
  7. package/dist/code-lab.d.ts +47 -38
  8. package/dist/code-lab.esm.js +918 -884
  9. package/dist/code-lab.js +917 -881
  10. package/dist/extensions/cpp.esm.js +33 -33
  11. package/dist/extensions/cpp.js +33 -33
  12. package/dist/extensions/python.esm.js +79 -49
  13. package/dist/extensions/python.js +79 -49
  14. package/dist/index.d.ts +1 -1
  15. package/dist/logger.d.ts +4 -20
  16. package/dist/modular-kernel.d.ts +0 -1
  17. package/dist/packages/core/src/errors.d.ts +5 -1
  18. package/dist/packages/fs/src/backends.d.ts +0 -27
  19. package/dist/packages/fs/src/index.d.ts +1 -1
  20. package/dist/packages/ui/src/html.d.ts +1 -0
  21. package/dist/packages/ui/src/index.d.ts +1 -0
  22. package/dist/{apps/web/src/index.d.ts → packages/ui/src/kernel.d.ts} +3 -2
  23. package/dist/packages/ui/src/observability.d.ts +1 -1
  24. package/dist/packages/ui/src/settings-dialog.d.ts +0 -1
  25. package/dist/preview-sw.js +1 -1
  26. package/dist/runtime.d.ts +3 -0
  27. package/dist/runtime.esm.js +2 -2
  28. package/dist/runtime.js +2 -2
  29. package/dist/schemas.d.ts +1 -1
  30. package/dist/shell.esm.js +277 -285
  31. package/dist/shell.js +277 -285
  32. package/dist/terminal.esm.js +2 -2
  33. package/dist/terminal.js +2 -2
  34. package/dist/workbench/editor.d.ts +0 -4
  35. package/dist/workbench/index.d.ts +0 -2
  36. package/dist/workbench/intellisense.d.ts +0 -1
  37. package/dist/workbench/xterm-adapter.d.ts +0 -1
  38. package/package.json +2 -4
  39. package/src/code-lab.css +0 -8086
  40. package/src/csp.ts +0 -590
  41. package/src/diagnostics.ts +0 -287
  42. package/src/extensions/cpp.ts +0 -2371
  43. package/src/extensions/guided-lab.ts +0 -68
  44. package/src/extensions/javascript.ts +0 -54
  45. package/src/extensions/python.ts +0 -1743
  46. package/src/extensions/typescript.ts +0 -85
  47. package/src/extensions/umbrella.ts +0 -5
  48. package/src/html.ts +0 -88
  49. package/src/index.ts +0 -129
  50. package/src/logger.ts +0 -139
  51. package/src/modular-kernel.ts +0 -7
  52. package/src/preview-sw.js +0 -296
  53. package/src/runtime/test-harness.ts +0 -57
  54. package/src/runtime.ts +0 -10565
  55. package/src/sample.html +0 -304
  56. package/src/schemas.ts +0 -366
  57. package/src/scm.ts +0 -2453
  58. package/src/search.ts +0 -433
  59. package/src/shell.ts +0 -10990
  60. package/src/storage.ts +0 -773
  61. package/src/terminal.ts +0 -1402
  62. package/src/workbench/command-palette.ts +0 -101
  63. package/src/workbench/diff-editor.ts +0 -472
  64. package/src/workbench/editor.ts +0 -49
  65. package/src/workbench/icons.ts +0 -255
  66. package/src/workbench/index.ts +0 -29
  67. package/src/workbench/intellisense.ts +0 -1884
  68. package/src/workbench/share.ts +0 -128
  69. package/src/workbench/xterm-adapter.ts +0 -1571
  70. package/src/workbench.ts +0 -21825
  71. package/src/zip.ts +0 -348
package/src/search.ts DELETED
@@ -1,433 +0,0 @@
1
- /**
2
- * @innovatorved/code-lab — High-Performance Cross-File Search & Replace Core
3
- * ============================================================================
4
- * Pure TypeScript implementation of workspace-wide text search and atomic multi-file
5
- * replacements. Supports regex, whole-word, case-sensitive matching, glob filtering,
6
- * line/column coordinate extraction, and match highlight snippets.
7
- *
8
- * Strict leaf module: fully typed, zero explicit any, zero empty catches.
9
- */
10
-
11
- export interface SearchOptions {
12
- query?: string;
13
- replacement?: string;
14
- caseSensitive?: boolean;
15
- wholeWord?: boolean;
16
- regex?: boolean;
17
- isRegex?: boolean;
18
- include?: string;
19
- includeGlob?: string;
20
- includePattern?: string | string[];
21
- exclude?: string;
22
- excludeGlob?: string;
23
- excludePattern?: string | string[];
24
- maxMatches?: number;
25
- maxMatchesPerFile?: number;
26
- targetFiles?: string[];
27
- }
28
-
29
- export interface SearchMatchItem {
30
- line: number;
31
- col: number;
32
- column?: number;
33
- length: number;
34
- matchText?: string;
35
- lineText: string;
36
- beforeSnippet?: string;
37
- afterSnippet?: string;
38
- matchIndex?: number;
39
- matchEndIndex?: number;
40
- }
41
-
42
- export interface SearchMatchGroup {
43
- file: string;
44
- matches: SearchMatchItem[];
45
- }
46
-
47
- export interface SearchResult extends Array<SearchMatchGroup> {
48
- matches: SearchMatchGroup[];
49
- totalMatches: number;
50
- fileCount: number;
51
- filesCount: number;
52
- query: string;
53
- durationMs?: number;
54
- error?: string;
55
- }
56
-
57
- export interface ReplaceResult {
58
- updatedFiles: Record<string, string>;
59
- files: Record<string, string>;
60
- replacedCount: number;
61
- filesAffected: string[];
62
- filesModified: number;
63
- }
64
-
65
- /**
66
- * Escapes regex special characters in a literal string.
67
- */
68
- export function escapeRegex(text: string): string {
69
- return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
70
- }
71
-
72
- /**
73
- * Normalizes a virtual workspace path (POSIX forward-slashes, no leading ./ or /).
74
- */
75
- export function normalizeSearchPath(filePath: string): string {
76
- let p = filePath.replace(/\\/g, '/');
77
- while (p.startsWith('./')) {
78
- p = p.slice(2);
79
- }
80
- while (p.startsWith('/')) {
81
- p = p.slice(1);
82
- }
83
- return p;
84
- }
85
-
86
- /**
87
- * Matches a file path against a glob or literal substring filter.
88
- * Supports comma-separated patterns (e.g. `*.ts, *.js`).
89
- */
90
- export function matchesGlob(filePath: string, pattern: string): boolean {
91
- if (!pattern || pattern === '*' || pattern === '**') return true;
92
- if (pattern.includes(',')) {
93
- const subPatterns = pattern
94
- .split(',')
95
- .map((s) => s.trim())
96
- .filter(Boolean);
97
- if (subPatterns.length > 1) {
98
- return subPatterns.some((sub) => matchesGlob(filePath, sub));
99
- }
100
- }
101
-
102
- const normPath = normalizeSearchPath(filePath);
103
- const normPattern = normalizeSearchPath(pattern.trim());
104
-
105
- if (normPattern === normPath) return true;
106
-
107
- // Plain substring match if no wildcards present
108
- if (!normPattern.includes('*') && !normPattern.includes('?')) {
109
- return normPath.includes(normPattern) || normPath.endsWith(normPattern);
110
- }
111
-
112
- // Convert glob pattern to regular expression
113
- let regexStr = '^';
114
- let i = 0;
115
- while (i < normPattern.length) {
116
- const c = normPattern[i];
117
- if (c === '*') {
118
- if (normPattern[i + 1] === '*') {
119
- i += 2;
120
- if (normPattern[i] === '/') {
121
- // `/**/` or leading `**/` matches zero or more directory segments
122
- regexStr += '(?:.*/)?';
123
- i++;
124
- } else {
125
- regexStr += '.*';
126
- }
127
- continue;
128
- } else {
129
- regexStr += '[^/]*';
130
- i++;
131
- continue;
132
- }
133
- } else if (c === '?') {
134
- regexStr += '[^/]';
135
- i++;
136
- continue;
137
- } else if ('./+^$()|[]{}\\'.includes(c)) {
138
- regexStr += '\\' + c;
139
- i++;
140
- continue;
141
- } else {
142
- regexStr += c;
143
- i++;
144
- }
145
- }
146
- regexStr += '$';
147
-
148
- try {
149
- const re = new RegExp(regexStr);
150
- if (re.test(normPath)) return true;
151
- // Also allow basename match when pattern has no directory separator (e.g. `*.ts` matching `src/app.ts`)
152
- if (!normPattern.includes('/')) {
153
- const baseName = normPath.split('/').pop() || normPath;
154
- if (re.test(baseName)) return true;
155
- }
156
- return false;
157
- } catch (err) {
158
- void err;
159
- return normPath.includes(normPattern.replace(/[*?]/g, ''));
160
- }
161
- }
162
-
163
- function checkFilter(path: string, filter?: string | string[]): boolean {
164
- if (!filter) return true;
165
- if (Array.isArray(filter)) {
166
- return filter.some((f) => matchesGlob(path, f));
167
- }
168
- return matchesGlob(path, filter);
169
- }
170
-
171
- function createSearchResult(
172
- groups: SearchMatchGroup[],
173
- totalMatches: number,
174
- fileCount: number,
175
- query: string,
176
- error?: string
177
- ): SearchResult {
178
- const arr = [...groups];
179
- const result = Object.assign(arr, {
180
- matches: groups,
181
- totalMatches,
182
- fileCount,
183
- filesCount: fileCount,
184
- query,
185
- durationMs: 0,
186
- error
187
- });
188
- return result as SearchResult;
189
- }
190
-
191
- /**
192
- * Searches across a map of virtual files for matching text or regex patterns.
193
- */
194
- export function searchInFiles(
195
- files: Record<string, string>,
196
- queryOrOptions: string | SearchOptions,
197
- optionsOrUndefined?: SearchOptions
198
- ): SearchResult {
199
- let query = '';
200
- let opts: SearchOptions = {};
201
-
202
- if (typeof queryOrOptions === 'string') {
203
- query = queryOrOptions;
204
- opts = optionsOrUndefined || {};
205
- } else if (queryOrOptions && typeof queryOrOptions === 'object') {
206
- opts = queryOrOptions;
207
- query = opts.query || '';
208
- }
209
-
210
- if (!query) {
211
- return createSearchResult([], 0, 0, query);
212
- }
213
-
214
- const isCaseSensitive = Boolean(opts.caseSensitive);
215
- const isWholeWord = Boolean(opts.wholeWord);
216
- const isRegex = Boolean(opts.regex || opts.isRegex);
217
- const maxMatches = opts.maxMatches ?? 10000;
218
- const maxMatchesPerFile = opts.maxMatchesPerFile ?? 1000;
219
-
220
- const includeFilter = opts.include || opts.includeGlob || opts.includePattern;
221
- const excludeFilter = opts.exclude || opts.excludeGlob || opts.excludePattern;
222
-
223
- let patternStr = isRegex ? query : escapeRegex(query);
224
- if (isWholeWord) {
225
- patternStr = `\\b${patternStr}\\b`;
226
- }
227
-
228
- let regex: RegExp = /(?:)/;
229
- try {
230
- regex = new RegExp(patternStr, isCaseSensitive ? 'g' : 'gi');
231
- } catch (err) {
232
- const _err = err;
233
- const msg =
234
- typeof _err === 'object' && _err && 'message' in _err
235
- ? String((_err as { message: unknown }).message)
236
- : 'Invalid regular expression';
237
- return createSearchResult([], 0, 0, query, msg);
238
- }
239
-
240
- const matchedGroups: SearchMatchGroup[] = [];
241
- let totalMatches = 0;
242
-
243
- for (const [filePath, content] of Object.entries(files)) {
244
- if (includeFilter && !checkFilter(filePath, includeFilter)) continue;
245
- if (excludeFilter && checkFilter(filePath, excludeFilter)) continue;
246
- if (opts.targetFiles && !opts.targetFiles.includes(filePath)) continue;
247
-
248
- const fileMatches: SearchMatchItem[] = [];
249
- const lines = content.split('\n');
250
-
251
- for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
252
- const lineText = lines[lineIndex];
253
- regex.lastIndex = 0;
254
- let m: RegExpExecArray | null = null;
255
-
256
- while ((m = regex.exec(lineText)) !== null) {
257
- const matchLen = m[0].length;
258
- const col = m.index + 1;
259
- fileMatches.push({
260
- line: lineIndex + 1,
261
- col,
262
- column: col,
263
- length: matchLen,
264
- matchText: m[0],
265
- lineText,
266
- beforeSnippet: lineText.slice(0, m.index),
267
- afterSnippet: lineText.slice(m.index + matchLen),
268
- matchIndex: m.index,
269
- matchEndIndex: m.index + matchLen
270
- });
271
- totalMatches++;
272
-
273
- if (fileMatches.length >= maxMatchesPerFile || totalMatches >= maxMatches) {
274
- break;
275
- }
276
-
277
- // Prevent infinite loop on zero-width match
278
- if (matchLen === 0) {
279
- regex.lastIndex++;
280
- if (regex.lastIndex > lineText.length) {
281
- break;
282
- }
283
- }
284
- }
285
-
286
- if (fileMatches.length >= maxMatchesPerFile || totalMatches >= maxMatches) {
287
- break;
288
- }
289
- }
290
-
291
- if (fileMatches.length > 0) {
292
- matchedGroups.push({
293
- file: filePath,
294
- matches: fileMatches
295
- });
296
- }
297
-
298
- if (totalMatches >= maxMatches) {
299
- break;
300
- }
301
- }
302
-
303
- return createSearchResult(matchedGroups, totalMatches, matchedGroups.length, query);
304
- }
305
-
306
- /**
307
- * Replaces occurrences of a query pattern across virtual workspace files.
308
- */
309
- export function replaceInFiles(
310
- files: Record<string, string>,
311
- arg2: string | SearchOptions,
312
- arg3?: string,
313
- arg4?: SearchOptions | string[]
314
- ): ReplaceResult {
315
- let query = '';
316
- let replacement = typeof arg3 === 'string' ? arg3 : '';
317
- let opts: SearchOptions = {};
318
- let targetFiles: string[] | undefined = undefined;
319
-
320
- if (typeof arg2 === 'string') {
321
- query = arg2;
322
- if (Array.isArray(arg4)) {
323
- targetFiles = arg4;
324
- } else if (arg4 && typeof arg4 === 'object') {
325
- opts = arg4;
326
- targetFiles = opts.targetFiles;
327
- }
328
- } else if (arg2 && typeof arg2 === 'object') {
329
- opts = arg2;
330
- query = opts.query || '';
331
- if (typeof arg3 !== 'string' && typeof opts.replacement === 'string') {
332
- replacement = opts.replacement;
333
- }
334
- if (Array.isArray(arg4)) {
335
- targetFiles = arg4;
336
- } else {
337
- targetFiles = opts.targetFiles;
338
- }
339
- }
340
-
341
- if (!query) {
342
- const copy = { ...files };
343
- return {
344
- updatedFiles: copy,
345
- files: copy,
346
- replacedCount: 0,
347
- filesAffected: [],
348
- filesModified: 0
349
- };
350
- }
351
-
352
- const isCaseSensitive = Boolean(opts.caseSensitive);
353
- const isWholeWord = Boolean(opts.wholeWord);
354
- const isRegex = Boolean(opts.regex || opts.isRegex);
355
-
356
- const includeFilter = opts.include || opts.includeGlob || opts.includePattern;
357
- const excludeFilter = opts.exclude || opts.excludeGlob || opts.excludePattern;
358
-
359
- let patternStr = isRegex ? query : escapeRegex(query);
360
- if (isWholeWord) {
361
- patternStr = `\\b${patternStr}\\b`;
362
- }
363
-
364
- let regex: RegExp = /(?:)/;
365
- try {
366
- regex = new RegExp(patternStr, isCaseSensitive ? 'g' : 'gi');
367
- } catch (err) {
368
- void err;
369
- const copy = { ...files };
370
- return {
371
- updatedFiles: copy,
372
- files: copy,
373
- replacedCount: 0,
374
- filesAffected: [],
375
- filesModified: 0
376
- };
377
- }
378
-
379
- const updatedFiles: Record<string, string> = { ...files };
380
- const filesAffected: string[] = [];
381
- let replacedCount = 0;
382
-
383
- for (const [filePath, content] of Object.entries(files)) {
384
- if (targetFiles && !targetFiles.includes(filePath)) continue;
385
- if (includeFilter && !checkFilter(filePath, includeFilter)) continue;
386
- if (excludeFilter && checkFilter(filePath, excludeFilter)) continue;
387
-
388
- const lines = content.split('\n');
389
- let countInFile = 0;
390
- const newLines: string[] = [];
391
-
392
- for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
393
- const lineText = lines[lineIdx];
394
- regex.lastIndex = 0;
395
- let lineMatches = 0;
396
- let m: RegExpExecArray | null;
397
- while ((m = regex.exec(lineText)) !== null) {
398
- lineMatches++;
399
- if (m[0].length === 0) {
400
- regex.lastIndex++;
401
- if (regex.lastIndex > lineText.length) {
402
- break;
403
- }
404
- }
405
- }
406
- if (lineMatches > 0) {
407
- countInFile += lineMatches;
408
- regex.lastIndex = 0;
409
- if (isRegex) {
410
- newLines.push(lineText.replace(regex, replacement));
411
- } else {
412
- newLines.push(lineText.replace(regex, () => replacement));
413
- }
414
- } else {
415
- newLines.push(lineText);
416
- }
417
- }
418
-
419
- if (countInFile > 0) {
420
- updatedFiles[filePath] = newLines.join('\n');
421
- filesAffected.push(filePath);
422
- replacedCount += countInFile;
423
- }
424
- }
425
-
426
- return {
427
- updatedFiles,
428
- files: updatedFiles,
429
- replacedCount,
430
- filesAffected,
431
- filesModified: filesAffected.length
432
- };
433
- }