@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.
- package/ARCHITECTURE.md +8 -4
- package/CHANGELOG.md +45 -0
- package/README.md +70 -158
- package/dist/apps/web/src/index.d.ts +34 -0
- package/dist/code-lab-sql.css +482 -0
- package/dist/code-lab-sql.d.ts +179 -0
- package/dist/code-lab-sql.esm.js +542 -0
- package/dist/code-lab-sql.umd.js +531 -0
- package/dist/code-lab.css +298 -2
- package/dist/code-lab.d.ts +110 -15
- package/dist/code-lab.esm.js +35284 -18253
- package/dist/code-lab.js +40434 -23431
- package/dist/code-lab.umd.js +65502 -0
- package/dist/diagnostics.d.ts +5 -0
- package/dist/extensions/cpp.esm.js +19532 -3772
- package/dist/extensions/cpp.js +19529 -3769
- package/dist/extensions/guided-lab.esm.js +19401 -3725
- package/dist/extensions/guided-lab.js +19400 -3724
- package/dist/extensions/python.d.ts +1 -0
- package/dist/extensions/python.esm.js +19666 -3843
- package/dist/extensions/python.js +19668 -3845
- package/dist/extensions/umbrella.d.ts +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/modular-kernel.d.ts +11 -0
- package/dist/packages/commands/src/index.d.ts +96 -0
- package/dist/packages/core/src/di.d.ts +36 -0
- package/dist/packages/core/src/disposable.d.ts +27 -0
- package/dist/packages/core/src/errors.d.ts +69 -0
- package/dist/packages/core/src/events.d.ts +38 -0
- package/dist/packages/core/src/index.d.ts +6 -0
- package/dist/packages/core/src/path.d.ts +14 -0
- package/dist/packages/core/src/registry.d.ts +23 -0
- package/dist/packages/editor/src/index.d.ts +118 -0
- package/dist/packages/fs/src/backends.d.ts +37 -0
- package/dist/packages/fs/src/index.d.ts +3 -0
- package/dist/packages/fs/src/types.d.ts +40 -0
- package/dist/packages/fs/src/vfs-service.d.ts +33 -0
- package/dist/packages/preview/src/index.d.ts +34 -0
- package/dist/packages/runtime/src/index.d.ts +47 -0
- package/dist/packages/settings/src/builtin-schemas.d.ts +15 -0
- package/dist/packages/settings/src/configuration-service.d.ts +100 -0
- package/dist/packages/settings/src/index.d.ts +4 -0
- package/dist/packages/settings/src/jsonc.d.ts +20 -0
- package/dist/packages/settings/src/schema.d.ts +28 -0
- package/dist/packages/sql/src/completions.d.ts +8 -0
- package/dist/packages/sql/src/diagnostics.d.ts +2 -0
- package/dist/packages/sql/src/formatter.d.ts +2 -0
- package/dist/packages/sql/src/index.d.ts +7 -0
- package/dist/packages/sql/src/sql-editor.d.ts +2 -0
- package/dist/packages/sql/src/styles.d.ts +2 -0
- package/dist/packages/sql/src/tokenizer.d.ts +13 -0
- package/dist/packages/sql/src/types.d.ts +130 -0
- package/dist/packages/terminal/src/index.d.ts +54 -0
- package/dist/packages/ui/src/index.d.ts +4 -0
- package/dist/packages/ui/src/observability.d.ts +22 -0
- package/dist/packages/ui/src/plugin-registry.d.ts +89 -0
- package/dist/packages/ui/src/settings-dialog.d.ts +25 -0
- package/dist/packages/ui/src/themes.d.ts +35 -0
- package/dist/preview-sw.js +82 -24
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.esm.js +503 -73
- package/dist/runtime.js +501 -73
- package/dist/schemas.d.ts +234 -814
- package/dist/schemas.esm.js +19401 -3725
- package/dist/schemas.js +19404 -3728
- package/dist/scm.d.ts +13 -2
- package/dist/search.d.ts +5 -1
- package/dist/shell.d.ts +1 -1
- package/dist/shell.esm.js +435 -54
- package/dist/shell.js +435 -54
- package/dist/terminal.esm.js +242 -54
- package/dist/terminal.js +242 -54
- package/dist/workbench/diff-editor.d.ts +1 -0
- package/dist/workbench/index.d.ts +1 -1
- package/dist/workbench/styles.d.ts +1 -1
- package/dist/zip.d.ts +4 -3
- package/package.json +37 -8
- package/packages/commands/README.md +7 -0
- package/packages/commands/package.json +16 -0
- package/packages/commands/src/index.ts +467 -0
- package/packages/commands/tsconfig.json +22 -0
- package/packages/core/README.md +12 -0
- package/packages/core/package.json +13 -0
- package/packages/core/src/di.ts +147 -0
- package/packages/core/src/disposable.ts +112 -0
- package/packages/core/src/errors.ts +205 -0
- package/packages/core/src/events.ts +157 -0
- package/packages/core/src/index.ts +49 -0
- package/packages/core/src/path.ts +118 -0
- package/packages/core/src/registry.ts +61 -0
- package/packages/core/tsconfig.json +19 -0
- package/packages/editor/README.md +9 -0
- package/packages/editor/package.json +18 -0
- package/packages/editor/src/index.ts +344 -0
- package/packages/editor/tsconfig.json +24 -0
- package/packages/fs/README.md +7 -0
- package/packages/fs/package.json +16 -0
- package/packages/fs/src/backends.ts +301 -0
- package/packages/fs/src/index.ts +18 -0
- package/packages/fs/src/types.ts +44 -0
- package/packages/fs/src/vfs-service.ts +257 -0
- package/packages/fs/tsconfig.json +22 -0
- package/packages/preview/README.md +3 -0
- package/packages/preview/package.json +16 -0
- package/packages/preview/src/index.ts +125 -0
- package/packages/preview/tsconfig.json +22 -0
- package/packages/runtime/README.md +3 -0
- package/packages/runtime/package.json +17 -0
- package/packages/runtime/src/index.ts +134 -0
- package/packages/runtime/tsconfig.json +23 -0
- package/packages/settings/README.md +7 -0
- package/packages/settings/package.json +16 -0
- package/packages/settings/src/builtin-schemas.ts +235 -0
- package/packages/settings/src/configuration-service.ts +543 -0
- package/packages/settings/src/index.ts +37 -0
- package/packages/settings/src/jsonc.ts +189 -0
- package/packages/settings/src/schema.ts +164 -0
- package/packages/settings/tsconfig.json +22 -0
- package/packages/sql/README.md +12 -0
- package/packages/sql/package.json +13 -0
- package/packages/sql/src/completions.ts +359 -0
- package/packages/sql/src/diagnostics.ts +200 -0
- package/packages/sql/src/formatter.ts +271 -0
- package/packages/sql/src/index.ts +54 -0
- package/packages/sql/src/sql-editor.ts +802 -0
- package/packages/sql/src/styles.ts +501 -0
- package/packages/sql/src/tokenizer.ts +457 -0
- package/packages/sql/src/types.ts +148 -0
- package/packages/sql/tsconfig.json +19 -0
- package/packages/terminal/README.md +3 -0
- package/packages/terminal/package.json +16 -0
- package/packages/terminal/src/index.ts +183 -0
- package/packages/terminal/tsconfig.json +22 -0
- package/packages/ui/README.md +8 -0
- package/packages/ui/package.json +18 -0
- package/packages/ui/src/index.ts +36 -0
- package/packages/ui/src/observability.ts +175 -0
- package/packages/ui/src/plugin-registry.ts +274 -0
- package/packages/ui/src/settings-dialog.ts +293 -0
- package/packages/ui/src/themes.ts +174 -0
- package/packages/ui/tsconfig.json +24 -0
- package/src/code-lab.css +298 -2
- package/src/csp.ts +7 -10
- package/src/diagnostics.ts +42 -3
- package/src/extensions/cpp.ts +105 -24
- package/src/extensions/python.ts +260 -116
- package/src/extensions/umbrella.ts +5 -0
- package/src/index.ts +1 -1
- package/src/modular-kernel.ts +11 -0
- package/src/preview-sw.js +73 -12
- package/src/runtime.ts +501 -74
- package/src/schemas.ts +62 -62
- package/src/scm.ts +106 -19
- package/src/search.ts +71 -27
- package/src/shell.ts +433 -53
- package/src/terminal.ts +239 -52
- package/src/workbench/diff-editor.ts +106 -18
- package/src/workbench/drawer.ts +17 -4
- package/src/workbench/guided-pane.ts +12 -2
- package/src/workbench/icons.ts +5 -2
- package/src/workbench/share.ts +37 -8
- package/src/workbench/styles.ts +2 -1
- package/src/workbench/toolbar.ts +15 -4
- package/src/workbench.ts +2877 -284
- package/src/zip.ts +29 -7
- package/dist/runtime/index.d.ts +0 -4
- package/dist/shell/coreutils/compilers-cli.d.ts +0 -24
- package/dist/shell/index.d.ts +0 -4
- package/src/runtime/index.ts +0 -5
- package/src/shell/coreutils/compilers-cli.ts +0 -103
- package/src/shell/index.ts +0 -5
package/src/zip.ts
CHANGED
|
@@ -57,8 +57,18 @@ export function computeCrc32(data: string | Uint8Array | ArrayBuffer): number {
|
|
|
57
57
|
return (crc ^ 0xffffffff) >>> 0;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
const DANGEROUS_PATH_SEGMENTS: ReadonlySet<string> = new Set([
|
|
61
|
+
'__proto__',
|
|
62
|
+
'constructor',
|
|
63
|
+
'prototype'
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
const MAX_ZIP_ENTRIES = 10000;
|
|
67
|
+
const MAX_ZIP_UNCOMPRESSED_BYTES = 100 * 1024 * 1024; // 100 MB
|
|
68
|
+
|
|
60
69
|
/**
|
|
61
|
-
* Sanitizes an archive entry path to prevent Zip-Slip directory traversal attacks
|
|
70
|
+
* Sanitizes an archive entry path to prevent Zip-Slip directory traversal attacks
|
|
71
|
+
* and prototype-pollution key injection.
|
|
62
72
|
* Normalizes backslashes, strips drive prefixes and leading slashes, and collapses
|
|
63
73
|
* or removes `..` and `.` segments so the resulting path is strictly relative.
|
|
64
74
|
*/
|
|
@@ -71,6 +81,9 @@ export function sanitizeZipPath(rawPath: string): string {
|
|
|
71
81
|
for (const part of parts) {
|
|
72
82
|
const trimmed = part.trim();
|
|
73
83
|
if (!trimmed || trimmed === '.') continue;
|
|
84
|
+
if (DANGEROUS_PATH_SEGMENTS.has(trimmed)) {
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
74
87
|
if (trimmed === '..') {
|
|
75
88
|
if (safeParts.length > 0) {
|
|
76
89
|
safeParts.pop();
|
|
@@ -117,9 +130,9 @@ interface ZipEntryInternal {
|
|
|
117
130
|
/**
|
|
118
131
|
* Creates a standard PKZip v2.0 archive from a map of file paths to contents.
|
|
119
132
|
*/
|
|
120
|
-
export
|
|
133
|
+
export function createZip(
|
|
121
134
|
files: Record<string, string | Uint8Array>
|
|
122
|
-
):
|
|
135
|
+
): Uint8Array {
|
|
123
136
|
const entries: ZipEntryInternal[] = [];
|
|
124
137
|
let localSectionSize = 0;
|
|
125
138
|
let centralDirSize = 0;
|
|
@@ -215,9 +228,9 @@ export async function createZip(
|
|
|
215
228
|
* Extracts a PKZip v2.0 archive into a UTF-8 file dictionary (`Record<string, string>`).
|
|
216
229
|
* Validates magic headers, checks boundaries, and sanitizes paths against Zip-Slip.
|
|
217
230
|
*/
|
|
218
|
-
export
|
|
231
|
+
export function extractZip(
|
|
219
232
|
data: Uint8Array | ArrayBuffer
|
|
220
|
-
):
|
|
233
|
+
): Record<string, string> {
|
|
221
234
|
const bytes = toUint8Array(data);
|
|
222
235
|
if (bytes.length < 22) {
|
|
223
236
|
throw new Error('Invalid or truncated ZIP archive: buffer shorter than minimum 22-byte EOCD record');
|
|
@@ -238,6 +251,9 @@ export async function extractZip(
|
|
|
238
251
|
}
|
|
239
252
|
|
|
240
253
|
const totalEntries = readUInt16LE(bytes, eocdOffset + 10);
|
|
254
|
+
if (totalEntries > MAX_ZIP_ENTRIES) {
|
|
255
|
+
throw new Error(`ZIP archive exceeds maximum allowed entry count (${MAX_ZIP_ENTRIES})`);
|
|
256
|
+
}
|
|
241
257
|
const centralDirSize = readUInt32LE(bytes, eocdOffset + 12);
|
|
242
258
|
const centralDirOffset = readUInt32LE(bytes, eocdOffset + 16);
|
|
243
259
|
|
|
@@ -245,8 +261,9 @@ export async function extractZip(
|
|
|
245
261
|
throw new Error('Corrupted ZIP archive: Central Directory extends past end of buffer');
|
|
246
262
|
}
|
|
247
263
|
|
|
248
|
-
const result: Record<string, string> =
|
|
264
|
+
const result: Record<string, string> = Object.create(null) as Record<string, string>;
|
|
249
265
|
let cdCursor = centralDirOffset;
|
|
266
|
+
let totalExtractedBytes = 0;
|
|
250
267
|
|
|
251
268
|
for (let i = 0; i < totalEntries; i++) {
|
|
252
269
|
if (cdCursor + 46 > bytes.length) {
|
|
@@ -299,6 +316,11 @@ export async function extractZip(
|
|
|
299
316
|
throw new Error(`Corrupted ZIP archive: file data truncated for ${safeName}`);
|
|
300
317
|
}
|
|
301
318
|
|
|
319
|
+
totalExtractedBytes += compressedSize;
|
|
320
|
+
if (totalExtractedBytes > MAX_ZIP_UNCOMPRESSED_BYTES) {
|
|
321
|
+
throw new Error(`ZIP archive exceeds maximum uncompressed size limit (${MAX_ZIP_UNCOMPRESSED_BYTES} bytes)`);
|
|
322
|
+
}
|
|
323
|
+
|
|
302
324
|
const rawFileBytes = bytes.subarray(dataStart, dataEnd);
|
|
303
325
|
if (compressionMethod !== 0) {
|
|
304
326
|
throw new Error(`Unsupported ZIP compression method ${compressionMethod} for ${safeName} (only Store=0 is supported)`);
|
|
@@ -314,7 +336,7 @@ export async function extractZip(
|
|
|
314
336
|
result[safeName] = textDecoder.decode(rawFileBytes);
|
|
315
337
|
}
|
|
316
338
|
|
|
317
|
-
return result;
|
|
339
|
+
return { ...result };
|
|
318
340
|
}
|
|
319
341
|
|
|
320
342
|
export default {
|
package/dist/runtime/index.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @innovatorved/code-lab — Shell Compiler Coreutils
|
|
3
|
-
* Provides `node`, `tsx`, `tsc`, `g++`, `clang++`, `python`, `python3`, `pytest`, `pip`.
|
|
4
|
-
*/
|
|
5
|
-
export interface ShellExecutionContext {
|
|
6
|
-
vfs: any;
|
|
7
|
-
cwd: string;
|
|
8
|
-
env: Record<string, string>;
|
|
9
|
-
resolvePath: (p: string) => string;
|
|
10
|
-
onStdout?: (text: string) => void;
|
|
11
|
-
onStderr?: (text: string) => void;
|
|
12
|
-
shell?: any;
|
|
13
|
-
}
|
|
14
|
-
export interface ShellExecResult {
|
|
15
|
-
code: number;
|
|
16
|
-
stdout: string;
|
|
17
|
-
stderr: string;
|
|
18
|
-
}
|
|
19
|
-
export declare const COMPILER_COREUTILS: {
|
|
20
|
-
python3(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult>;
|
|
21
|
-
python(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult>;
|
|
22
|
-
pytest(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult>;
|
|
23
|
-
pip(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult>;
|
|
24
|
-
};
|
package/dist/shell/index.d.ts
DELETED
package/src/runtime/index.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @innovatorved/code-lab — Shell Compiler Coreutils
|
|
3
|
-
* Provides `node`, `tsx`, `tsc`, `g++`, `clang++`, `python`, `python3`, `pytest`, `pip`.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface ShellExecutionContext {
|
|
7
|
-
vfs: any;
|
|
8
|
-
cwd: string;
|
|
9
|
-
env: Record<string, string>;
|
|
10
|
-
resolvePath: (p: string) => string;
|
|
11
|
-
onStdout?: (text: string) => void;
|
|
12
|
-
onStderr?: (text: string) => void;
|
|
13
|
-
shell?: any;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface ShellExecResult {
|
|
17
|
-
code: number;
|
|
18
|
-
stdout: string;
|
|
19
|
-
stderr: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const COMPILER_COREUTILS = {
|
|
23
|
-
async python3(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult> {
|
|
24
|
-
if (args.length === 0) {
|
|
25
|
-
return { code: 0, stdout: 'Python 3.12.8 (CPython WebAssembly via Pyodide)\n', stderr: '' };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (args[0] === '--version' || args[0] === '-V') {
|
|
29
|
-
return { code: 0, stdout: 'Python 3.12.8 (CPython WebAssembly via Pyodide)\n', stderr: '' };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let codeToRun: string | undefined;
|
|
33
|
-
let entryFile: string | undefined;
|
|
34
|
-
|
|
35
|
-
if (args[0] === '-c' && args.length > 1) {
|
|
36
|
-
codeToRun = args[1];
|
|
37
|
-
} else if (!args[0].startsWith('-')) {
|
|
38
|
-
entryFile = ctx.resolvePath(args[0]);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const pyCompiler =
|
|
42
|
-
(ctx.shell && ctx.shell.options && ctx.shell.options.pythonCompiler) ||
|
|
43
|
-
(typeof globalThis !== 'undefined' && (globalThis as any).__codelabPythonCompiler) ||
|
|
44
|
-
(typeof window !== 'undefined' && (window as any).__codelabPythonCompiler);
|
|
45
|
-
|
|
46
|
-
if (typeof pyCompiler !== 'function') {
|
|
47
|
-
return {
|
|
48
|
-
code: 1,
|
|
49
|
-
stdout: '',
|
|
50
|
-
stderr: 'python3: Python WebAssembly toolchain is not loaded. Enable pythonExtension from "@innovatorved/code-lab/extensions/python".\n'
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
let stdoutAcc = '';
|
|
55
|
-
let stderrAcc = '';
|
|
56
|
-
|
|
57
|
-
const res = await pyCompiler({
|
|
58
|
-
entry: entryFile,
|
|
59
|
-
source: codeToRun,
|
|
60
|
-
vfs: ctx.vfs,
|
|
61
|
-
onStdout: (t: string) => {
|
|
62
|
-
stdoutAcc += t;
|
|
63
|
-
if (ctx.onStdout) ctx.onStdout(t);
|
|
64
|
-
},
|
|
65
|
-
onStderr: (t: string) => {
|
|
66
|
-
stderrAcc += t;
|
|
67
|
-
if (ctx.onStderr) ctx.onStderr(t);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
code: res.ok ? 0 : (res.exitCode || 1),
|
|
73
|
-
stdout: stdoutAcc,
|
|
74
|
-
stderr: stderrAcc
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
async python(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult> {
|
|
79
|
-
return COMPILER_COREUTILS.python3(args, ctx);
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
async pytest(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult> {
|
|
83
|
-
const testFiles = args.filter((a) => !a.startsWith('-'));
|
|
84
|
-
const target = testFiles[0] || 'test.py';
|
|
85
|
-
return COMPILER_COREUTILS.python3([target], ctx);
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
async pip(args: string[], ctx: ShellExecutionContext): Promise<ShellExecResult> {
|
|
89
|
-
void ctx;
|
|
90
|
-
if (args.length === 0 || args[0] === '--version' || args[0] === '-V') {
|
|
91
|
-
return { code: 0, stdout: 'pip 24.0 from /usr/lib/python/pip (python 3.12)\n', stderr: '' };
|
|
92
|
-
}
|
|
93
|
-
if (args[0] === 'install') {
|
|
94
|
-
const pkgs = args.slice(1).filter((p) => !p.startsWith('-'));
|
|
95
|
-
return {
|
|
96
|
-
code: 0,
|
|
97
|
-
stdout: `Successfully installed ${pkgs.join(', ') || 'packages'}\n`,
|
|
98
|
-
stderr: ''
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return { code: 0, stdout: 'pip 24.0 (Pyodide micropip)\n', stderr: '' };
|
|
102
|
-
}
|
|
103
|
-
};
|