@innovatorved/code-lab 0.3.2 → 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 +5 -3
- package/CHANGELOG.md +20 -0
- package/README.md +70 -168
- 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 +246 -0
- package/dist/code-lab.d.ts +110 -15
- package/dist/code-lab.esm.js +34265 -18104
- package/dist/code-lab.js +33186 -17053
- package/dist/code-lab.umd.js +65502 -0
- package/dist/extensions/cpp.esm.js +19478 -3760
- package/dist/extensions/cpp.js +19475 -3757
- 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 +19576 -3766
- package/dist/extensions/python.js +19576 -3766
- 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 +53 -12
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.esm.js +467 -44
- package/dist/runtime.js +465 -44
- package/dist/schemas.d.ts +234 -814
- package/dist/schemas.esm.js +19401 -3725
- package/dist/schemas.js +19404 -3728
- package/dist/shell.d.ts +1 -1
- package/dist/shell.esm.js +364 -39
- package/dist/shell.js +364 -39
- package/dist/terminal.esm.js +62 -3
- package/dist/terminal.js +62 -3
- package/dist/workbench/diff-editor.d.ts +1 -0
- 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 +246 -0
- package/src/extensions/cpp.ts +58 -15
- package/src/extensions/python.ts +156 -24
- 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 +52 -11
- package/src/runtime.ts +466 -46
- package/src/schemas.ts +62 -62
- package/src/shell.ts +363 -39
- package/src/terminal.ts +60 -2
- package/src/workbench/diff-editor.ts +66 -6
- package/src/workbench/icons.ts +5 -2
- package/src/workbench.ts +2410 -220
- 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/dist/shell.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ============================================================
|
|
3
|
-
* @innovatorved/code-lab v0.
|
|
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
|
|
@@ -87,6 +87,7 @@ var CodeLabLogger = (() => {
|
|
|
87
87
|
} catch (err) {
|
|
88
88
|
sinkError = err;
|
|
89
89
|
}
|
|
90
|
+
void sinkError;
|
|
90
91
|
}
|
|
91
92
|
const consoleObj = typeof console !== "undefined" ? console : null;
|
|
92
93
|
const fn = consoleObj ? consoleObj[level] : null;
|
|
@@ -1713,9 +1714,11 @@ var CodeLabLogger = (() => {
|
|
|
1713
1714
|
function createFallbackVfs() {
|
|
1714
1715
|
const files = new Map();
|
|
1715
1716
|
const dirs = new Set(['/', '/tmp', '/workspace', '/etc', '/home', '/home/user']);
|
|
1717
|
+
let _activeStdin = '';
|
|
1716
1718
|
|
|
1717
1719
|
function norm(p) {
|
|
1718
|
-
|
|
1720
|
+
const s = String(p);
|
|
1721
|
+
return PosixPath.normalize(s.startsWith('/') ? s : '/workspace/' + s);
|
|
1719
1722
|
}
|
|
1720
1723
|
|
|
1721
1724
|
const emitter = {
|
|
@@ -1803,6 +1806,12 @@ var CodeLabLogger = (() => {
|
|
|
1803
1806
|
return Array.from(children).sort();
|
|
1804
1807
|
},
|
|
1805
1808
|
readFileSync(p, encoding) {
|
|
1809
|
+
if (p === 0 || p === '/dev/stdin') {
|
|
1810
|
+
if (!encoding || encoding === 'buffer') {
|
|
1811
|
+
return new TextEncoder().encode(_activeStdin);
|
|
1812
|
+
}
|
|
1813
|
+
return _activeStdin;
|
|
1814
|
+
}
|
|
1806
1815
|
const np = norm(p);
|
|
1807
1816
|
const f = files.get(np);
|
|
1808
1817
|
if (!f) {
|
|
@@ -1815,6 +1824,9 @@ var CodeLabLogger = (() => {
|
|
|
1815
1824
|
}
|
|
1816
1825
|
return f.data;
|
|
1817
1826
|
},
|
|
1827
|
+
_setActiveStdin(text) {
|
|
1828
|
+
_activeStdin = text === null || text === undefined ? '' : String(text);
|
|
1829
|
+
},
|
|
1818
1830
|
writeFileSync(p, data) {
|
|
1819
1831
|
const np = norm(p);
|
|
1820
1832
|
const parent = PosixPath.dirname(np);
|
|
@@ -3073,9 +3085,31 @@ var CodeLabLogger = (() => {
|
|
|
3073
3085
|
'.gif': 'image/gif',
|
|
3074
3086
|
'.webp': 'image/webp',
|
|
3075
3087
|
'.ico': 'image/x-icon',
|
|
3088
|
+
'.woff': 'font/woff',
|
|
3089
|
+
'.woff2': 'font/woff2',
|
|
3090
|
+
'.ttf': 'font/ttf',
|
|
3091
|
+
'.otf': 'font/otf',
|
|
3092
|
+
'.wasm': 'application/wasm',
|
|
3093
|
+
'.pdf': 'application/pdf',
|
|
3094
|
+
'.mp3': 'audio/mpeg',
|
|
3095
|
+
'.mp4': 'video/mp4',
|
|
3096
|
+
'.webm': 'video/webm',
|
|
3076
3097
|
'.txt': 'text/plain; charset=utf-8'
|
|
3077
3098
|
};
|
|
3078
3099
|
|
|
3100
|
+
function isBinaryPreviewMime(mime) {
|
|
3101
|
+
const clean = String(mime || '').toLowerCase().split(';')[0].trim();
|
|
3102
|
+
if (!clean) return false;
|
|
3103
|
+
return !(
|
|
3104
|
+
clean.startsWith('text/') ||
|
|
3105
|
+
clean === 'application/javascript' ||
|
|
3106
|
+
clean === 'application/json' ||
|
|
3107
|
+
clean === 'application/xml' ||
|
|
3108
|
+
clean === 'application/xhtml+xml' ||
|
|
3109
|
+
clean === 'image/svg+xml'
|
|
3110
|
+
);
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3079
3113
|
function previewMimeFor(p) {
|
|
3080
3114
|
const lower = String(p).toLowerCase();
|
|
3081
3115
|
const dot = lower.lastIndexOf('.');
|
|
@@ -3259,7 +3293,8 @@ var CodeLabLogger = (() => {
|
|
|
3259
3293
|
|
|
3260
3294
|
function injectPreviewExtras(html, importMap) {
|
|
3261
3295
|
let out = html;
|
|
3262
|
-
const
|
|
3296
|
+
const safeImportMapJson = JSON.stringify({ imports: importMap }, null, 2).replace(/</g, '\\u003c');
|
|
3297
|
+
const importMapTag = `<script type="importmap">\n${safeImportMapJson}\n</script>`;
|
|
3263
3298
|
if (/<head[^>]*>/i.test(out)) {
|
|
3264
3299
|
out = out.replace(/<head[^>]*>/i, (m) => `${m}\n ${importMapTag}`);
|
|
3265
3300
|
} else {
|
|
@@ -3515,6 +3550,20 @@ var CodeLabLogger = (() => {
|
|
|
3515
3550
|
);
|
|
3516
3551
|
}
|
|
3517
3552
|
|
|
3553
|
+
const mimeType = previewMimeFor(target);
|
|
3554
|
+
if (isBinaryPreviewMime(mimeType)) {
|
|
3555
|
+
let rawBytes = null;
|
|
3556
|
+
try {
|
|
3557
|
+
rawBytes = ctx.vfs.readFileSync(target);
|
|
3558
|
+
} catch (err) {
|
|
3559
|
+
_shellLogger.debug('Binary preview asset read failed.', target, err);
|
|
3560
|
+
}
|
|
3561
|
+
const binaryBody = rawBytes instanceof Uint8Array
|
|
3562
|
+
? rawBytes
|
|
3563
|
+
: (typeof rawBytes === 'string' ? new TextEncoder().encode(rawBytes) : new Uint8Array(0));
|
|
3564
|
+
return new Response(binaryBody, { status: 200, headers: { 'content-type': mimeType } });
|
|
3565
|
+
}
|
|
3566
|
+
|
|
3518
3567
|
let body = readText(target);
|
|
3519
3568
|
if (body === null) body = '';
|
|
3520
3569
|
if (/\.html?$/i.test(target)) {
|
|
@@ -3530,7 +3579,7 @@ var CodeLabLogger = (() => {
|
|
|
3530
3579
|
}
|
|
3531
3580
|
}
|
|
3532
3581
|
|
|
3533
|
-
return new Response(body, { status: 200, headers: { 'content-type':
|
|
3582
|
+
return new Response(body, { status: 200, headers: { 'content-type': mimeType } });
|
|
3534
3583
|
};
|
|
3535
3584
|
|
|
3536
3585
|
const pid = (ctx.shell && typeof ctx.shell.nextPid === 'number') ? ctx.shell.nextPid++ : (ctx.pid || 1000);
|
|
@@ -6112,6 +6161,9 @@ var CodeLabLogger = (() => {
|
|
|
6112
6161
|
mode: 'repl',
|
|
6113
6162
|
replCode: code,
|
|
6114
6163
|
printReplResult: false,
|
|
6164
|
+
stdin: ctx.stdin || '',
|
|
6165
|
+
env: ctx.env,
|
|
6166
|
+
cwd: ctx.cwd,
|
|
6115
6167
|
vfs: ctx.vfs,
|
|
6116
6168
|
activePortTable: ctx.shell.portTable,
|
|
6117
6169
|
pid: ctx.pid,
|
|
@@ -6129,6 +6181,9 @@ var CodeLabLogger = (() => {
|
|
|
6129
6181
|
mode: 'repl',
|
|
6130
6182
|
replCode: code,
|
|
6131
6183
|
printReplResult: true,
|
|
6184
|
+
stdin: ctx.stdin || '',
|
|
6185
|
+
env: ctx.env,
|
|
6186
|
+
cwd: ctx.cwd,
|
|
6132
6187
|
vfs: ctx.vfs,
|
|
6133
6188
|
activePortTable: ctx.shell.portTable,
|
|
6134
6189
|
pid: ctx.pid,
|
|
@@ -6168,6 +6223,9 @@ var CodeLabLogger = (() => {
|
|
|
6168
6223
|
const res = await executeInVirtualRuntime({
|
|
6169
6224
|
mode: 'test',
|
|
6170
6225
|
entry: f,
|
|
6226
|
+
stdin: ctx.stdin || '',
|
|
6227
|
+
env: ctx.env,
|
|
6228
|
+
cwd: ctx.cwd,
|
|
6171
6229
|
vfs: ctx.vfs,
|
|
6172
6230
|
activePortTable: ctx.shell.portTable,
|
|
6173
6231
|
pid: ctx.pid,
|
|
@@ -6193,6 +6251,9 @@ var CodeLabLogger = (() => {
|
|
|
6193
6251
|
mode: 'run',
|
|
6194
6252
|
entry: scriptFile,
|
|
6195
6253
|
argv: ['node', scriptFile, ...scriptArgs],
|
|
6254
|
+
stdin: ctx.stdin || '',
|
|
6255
|
+
env: ctx.env,
|
|
6256
|
+
cwd: ctx.cwd,
|
|
6196
6257
|
vfs: ctx.vfs,
|
|
6197
6258
|
activePortTable: ctx.shell.portTable,
|
|
6198
6259
|
pid: ctx.pid,
|
|
@@ -6360,6 +6421,9 @@ var CodeLabLogger = (() => {
|
|
|
6360
6421
|
const res = await pyCompiler({
|
|
6361
6422
|
entry: entryFile,
|
|
6362
6423
|
source: codeToRun,
|
|
6424
|
+
stdin: ctx.stdin || '',
|
|
6425
|
+
env: ctx.env,
|
|
6426
|
+
cwd: ctx.cwd,
|
|
6363
6427
|
vfs: ctx.vfs,
|
|
6364
6428
|
onStdout: (t) => {
|
|
6365
6429
|
outText += t;
|
|
@@ -6426,9 +6490,9 @@ var CodeLabLogger = (() => {
|
|
|
6426
6490
|
};
|
|
6427
6491
|
}
|
|
6428
6492
|
return {
|
|
6429
|
-
code:
|
|
6430
|
-
stdout:
|
|
6431
|
-
stderr: ''
|
|
6493
|
+
code: 1,
|
|
6494
|
+
stdout: '',
|
|
6495
|
+
stderr: 'pip: Python WebAssembly toolchain is not enabled. Enable pythonExtension from "@innovatorved/code-lab/extensions/python".\n'
|
|
6432
6496
|
};
|
|
6433
6497
|
}
|
|
6434
6498
|
return { code: 0, stdout: 'pip 24.0 (Pyodide micropip)\n', stderr: '' };
|
|
@@ -6546,6 +6610,9 @@ var CodeLabLogger = (() => {
|
|
|
6546
6610
|
mode: 'repl',
|
|
6547
6611
|
replCode: code,
|
|
6548
6612
|
printReplResult: false,
|
|
6613
|
+
stdin: ctx.stdin || '',
|
|
6614
|
+
env: ctx.env,
|
|
6615
|
+
cwd: ctx.cwd,
|
|
6549
6616
|
vfs: ctx.vfs,
|
|
6550
6617
|
activePortTable: ctx.shell.portTable,
|
|
6551
6618
|
pid: ctx.pid,
|
|
@@ -6585,6 +6652,9 @@ var CodeLabLogger = (() => {
|
|
|
6585
6652
|
const res = await executeInVirtualRuntime({
|
|
6586
6653
|
mode: 'test',
|
|
6587
6654
|
entry: f,
|
|
6655
|
+
stdin: ctx.stdin || '',
|
|
6656
|
+
env: ctx.env,
|
|
6657
|
+
cwd: ctx.cwd,
|
|
6588
6658
|
vfs: ctx.vfs,
|
|
6589
6659
|
activePortTable: ctx.shell.portTable,
|
|
6590
6660
|
pid: ctx.pid,
|
|
@@ -6612,6 +6682,9 @@ var CodeLabLogger = (() => {
|
|
|
6612
6682
|
mode: 'run',
|
|
6613
6683
|
entry: resolved,
|
|
6614
6684
|
argv: ['bun', resolved, ...scriptArgs],
|
|
6685
|
+
stdin: ctx.stdin || '',
|
|
6686
|
+
env: ctx.env,
|
|
6687
|
+
cwd: ctx.cwd,
|
|
6615
6688
|
vfs: ctx.vfs,
|
|
6616
6689
|
activePortTable: ctx.shell.portTable,
|
|
6617
6690
|
pid: ctx.pid,
|
|
@@ -6636,6 +6709,9 @@ var CodeLabLogger = (() => {
|
|
|
6636
6709
|
mode: 'run',
|
|
6637
6710
|
entry: resolved,
|
|
6638
6711
|
argv: ['bun', resolved, ...scriptArgs],
|
|
6712
|
+
stdin: ctx.stdin || '',
|
|
6713
|
+
env: ctx.env,
|
|
6714
|
+
cwd: ctx.cwd,
|
|
6639
6715
|
vfs: ctx.vfs,
|
|
6640
6716
|
activePortTable: ctx.shell.portTable,
|
|
6641
6717
|
pid: ctx.pid,
|
|
@@ -6917,12 +6993,24 @@ var CodeLabLogger = (() => {
|
|
|
6917
6993
|
if (!method) method = 'GET';
|
|
6918
6994
|
|
|
6919
6995
|
const portTable = (ctx.shell && ctx.shell.portTable) || null;
|
|
6996
|
+
const fetchImpl = (ctx.shell && ctx.shell.options && typeof (ctx.shell.options.fetch || ctx.shell.options.fetchImpl) === 'function')
|
|
6997
|
+
? (ctx.shell.options.fetch || ctx.shell.options.fetchImpl)
|
|
6998
|
+
: fetch;
|
|
6999
|
+
let isLoopback = false;
|
|
7000
|
+
try {
|
|
7001
|
+
const parsedUrl = new URL(url);
|
|
7002
|
+
const host = parsedUrl.hostname.toLowerCase();
|
|
7003
|
+
isLoopback = host === 'localhost' || host === '127.0.0.1' || host === '0.0.0.0' || host === '::1' || host === '[::1]';
|
|
7004
|
+
} catch (err) {
|
|
7005
|
+
_shellLogger.debug('curl URL parse fallback', url, err);
|
|
7006
|
+
}
|
|
6920
7007
|
let resp = null;
|
|
6921
7008
|
let lastErr = null;
|
|
7009
|
+
const maxAttempts = portTable && isLoopback ? 25 : 1;
|
|
6922
7010
|
|
|
6923
|
-
for (let attempt = 0; attempt <
|
|
7011
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
6924
7012
|
try {
|
|
6925
|
-
if (portTable) {
|
|
7013
|
+
if (portTable && isLoopback) {
|
|
6926
7014
|
resp = await portTable.dispatchRequest(url, {
|
|
6927
7015
|
method,
|
|
6928
7016
|
headers,
|
|
@@ -6931,7 +7019,7 @@ var CodeLabLogger = (() => {
|
|
|
6931
7019
|
lastErr = null;
|
|
6932
7020
|
break;
|
|
6933
7021
|
} else {
|
|
6934
|
-
resp = await
|
|
7022
|
+
resp = await fetchImpl(url, {
|
|
6935
7023
|
method,
|
|
6936
7024
|
headers,
|
|
6937
7025
|
body: data
|
|
@@ -6942,7 +7030,9 @@ var CodeLabLogger = (() => {
|
|
|
6942
7030
|
} catch (err) {
|
|
6943
7031
|
lastErr = err;
|
|
6944
7032
|
if (err && err.chaosEffect) break;
|
|
6945
|
-
|
|
7033
|
+
if (attempt + 1 < maxAttempts) {
|
|
7034
|
+
await new Promise(r => setTimeout(r, 15));
|
|
7035
|
+
}
|
|
6946
7036
|
}
|
|
6947
7037
|
}
|
|
6948
7038
|
|
|
@@ -7021,6 +7111,17 @@ var CodeLabLogger = (() => {
|
|
|
7021
7111
|
concurrency = Math.min(concurrency, totalRequests);
|
|
7022
7112
|
|
|
7023
7113
|
const portTable = (ctx.shell && ctx.shell.portTable) || null;
|
|
7114
|
+
const fetchImpl = (ctx.shell && ctx.shell.options && typeof (ctx.shell.options.fetch || ctx.shell.options.fetchImpl) === 'function')
|
|
7115
|
+
? (ctx.shell.options.fetch || ctx.shell.options.fetchImpl)
|
|
7116
|
+
: fetch;
|
|
7117
|
+
let isLoopback = false;
|
|
7118
|
+
try {
|
|
7119
|
+
const parsedUrl = new URL(url);
|
|
7120
|
+
const host = parsedUrl.hostname.toLowerCase();
|
|
7121
|
+
isLoopback = host === 'localhost' || host === '127.0.0.1' || host === '0.0.0.0' || host === '::1' || host === '[::1]';
|
|
7122
|
+
} catch (err) {
|
|
7123
|
+
_shellLogger.debug('hey URL parse fallback', url, err);
|
|
7124
|
+
}
|
|
7024
7125
|
const latencies = [];
|
|
7025
7126
|
const statusCounts = {};
|
|
7026
7127
|
const errorCounts = {};
|
|
@@ -7036,10 +7137,10 @@ var CodeLabLogger = (() => {
|
|
|
7036
7137
|
const reqStart = (typeof performance !== 'undefined' && performance.now) ? performance.now() : Date.now();
|
|
7037
7138
|
try {
|
|
7038
7139
|
let resp;
|
|
7039
|
-
if (portTable) {
|
|
7140
|
+
if (portTable && isLoopback) {
|
|
7040
7141
|
resp = await portTable.dispatchRequest(url, { method, headers: { ...headers }, body });
|
|
7041
7142
|
} else {
|
|
7042
|
-
resp = await
|
|
7143
|
+
resp = await fetchImpl(url, { method, headers: { ...headers }, body });
|
|
7043
7144
|
}
|
|
7044
7145
|
const reqEnd = (typeof performance !== 'undefined' && performance.now) ? performance.now() : Date.now();
|
|
7045
7146
|
const dur = Math.max(0.05, reqEnd - reqStart);
|
|
@@ -7972,6 +8073,15 @@ var CodeLabLogger = (() => {
|
|
|
7972
8073
|
}
|
|
7973
8074
|
|
|
7974
8075
|
this.history.push(trimmed);
|
|
8076
|
+
if (this.history.length > 1000) {
|
|
8077
|
+
this.history.splice(0, this.history.length - 1000);
|
|
8078
|
+
}
|
|
8079
|
+
if (this.jobs.size > 256) {
|
|
8080
|
+
for (const [jid, j] of this.jobs.entries()) {
|
|
8081
|
+
if (this.jobs.size <= 256) break;
|
|
8082
|
+
if (j && j.status !== 'Running') this.jobs.delete(jid);
|
|
8083
|
+
}
|
|
8084
|
+
}
|
|
7975
8085
|
|
|
7976
8086
|
const cwd = execOptions.cwd ? this.resolvePath(execOptions.cwd) : this.cwd;
|
|
7977
8087
|
this.cwd = cwd;
|
|
@@ -8041,6 +8151,10 @@ var CodeLabLogger = (() => {
|
|
|
8041
8151
|
if (res.aborted || (execOptions.signal && execOptions.signal.aborted)) {
|
|
8042
8152
|
return { code: 130, exitCode: 130, stdout: combinedStdout, stderr: combinedStderr, aborted: true };
|
|
8043
8153
|
}
|
|
8154
|
+
if (res.controlFlow && res.controlFlow.type === 'exit') {
|
|
8155
|
+
lastCode = res.controlFlow.code !== undefined ? res.controlFlow.code : lastCode;
|
|
8156
|
+
break;
|
|
8157
|
+
}
|
|
8044
8158
|
}
|
|
8045
8159
|
}
|
|
8046
8160
|
|
|
@@ -8051,6 +8165,218 @@ var CodeLabLogger = (() => {
|
|
|
8051
8165
|
return this.execute(commandLine, execOptions);
|
|
8052
8166
|
}
|
|
8053
8167
|
|
|
8168
|
+
async _expandHeredocBody(rawBody, cmdEnv) {
|
|
8169
|
+
const src = String(rawBody || '');
|
|
8170
|
+
let out = '';
|
|
8171
|
+
let i = 0;
|
|
8172
|
+
while (i < src.length) {
|
|
8173
|
+
const ch = src[i];
|
|
8174
|
+
if (ch === '\\' && i + 1 < src.length && '$`\\\n'.includes(src[i + 1])) {
|
|
8175
|
+
if (src[i + 1] === '\n') {
|
|
8176
|
+
i += 2;
|
|
8177
|
+
continue;
|
|
8178
|
+
}
|
|
8179
|
+
out += src[i + 1];
|
|
8180
|
+
i += 2;
|
|
8181
|
+
continue;
|
|
8182
|
+
}
|
|
8183
|
+
if (ch === '$' && src[i + 1] === '(' && src[i + 2] === '(') {
|
|
8184
|
+
i += 3;
|
|
8185
|
+
let depth = 2;
|
|
8186
|
+
let expr = '';
|
|
8187
|
+
while (i < src.length && depth > 0) {
|
|
8188
|
+
if (src[i] === '(') { depth++; expr += '('; i++; }
|
|
8189
|
+
else if (src[i] === ')') {
|
|
8190
|
+
if (depth === 2 && src[i + 1] === ')') { depth = 0; i += 2; break; }
|
|
8191
|
+
depth--;
|
|
8192
|
+
if (depth > 0) expr += ')';
|
|
8193
|
+
i++;
|
|
8194
|
+
} else {
|
|
8195
|
+
expr += src[i++];
|
|
8196
|
+
}
|
|
8197
|
+
}
|
|
8198
|
+
out += evaluateArithmetic(expr, cmdEnv, this.env);
|
|
8199
|
+
continue;
|
|
8200
|
+
}
|
|
8201
|
+
if (ch === '$' && src[i + 1] === '(') {
|
|
8202
|
+
i += 2;
|
|
8203
|
+
let depth = 1;
|
|
8204
|
+
let sub = '';
|
|
8205
|
+
while (i < src.length && depth > 0) {
|
|
8206
|
+
if (src[i] === '(') depth++;
|
|
8207
|
+
else if (src[i] === ')') depth--;
|
|
8208
|
+
if (depth > 0) sub += src[i];
|
|
8209
|
+
i++;
|
|
8210
|
+
}
|
|
8211
|
+
out += await this._executeSubshell(sub, cmdEnv);
|
|
8212
|
+
continue;
|
|
8213
|
+
}
|
|
8214
|
+
if (ch === '`') {
|
|
8215
|
+
i++;
|
|
8216
|
+
let sub = '';
|
|
8217
|
+
while (i < src.length && src[i] !== '`') sub += src[i++];
|
|
8218
|
+
if (i < src.length && src[i] === '`') i++;
|
|
8219
|
+
out += await this._executeSubshell(sub, cmdEnv);
|
|
8220
|
+
continue;
|
|
8221
|
+
}
|
|
8222
|
+
if (ch === '$') {
|
|
8223
|
+
i++;
|
|
8224
|
+
if (src[i] === '{') {
|
|
8225
|
+
i++;
|
|
8226
|
+
let varName = '';
|
|
8227
|
+
let bDepth = 1;
|
|
8228
|
+
while (i < src.length && bDepth > 0) {
|
|
8229
|
+
if (src[i] === '{') bDepth++;
|
|
8230
|
+
else if (src[i] === '}') bDepth--;
|
|
8231
|
+
if (bDepth > 0) varName += src[i];
|
|
8232
|
+
i++;
|
|
8233
|
+
}
|
|
8234
|
+
out += this._expandVariable(varName, cmdEnv);
|
|
8235
|
+
} else if (i < src.length && /[0-9?!$#@*]/.test(src[i])) {
|
|
8236
|
+
out += this._expandVariable(src[i++], cmdEnv);
|
|
8237
|
+
} else if (i < src.length && /[a-zA-Z_]/.test(src[i])) {
|
|
8238
|
+
let varName = '';
|
|
8239
|
+
while (i < src.length && /[a-zA-Z0-9_]/.test(src[i])) varName += src[i++];
|
|
8240
|
+
out += this._expandVariable(varName, cmdEnv);
|
|
8241
|
+
} else {
|
|
8242
|
+
out += '$';
|
|
8243
|
+
}
|
|
8244
|
+
continue;
|
|
8245
|
+
}
|
|
8246
|
+
out += ch;
|
|
8247
|
+
i++;
|
|
8248
|
+
}
|
|
8249
|
+
return out;
|
|
8250
|
+
}
|
|
8251
|
+
|
|
8252
|
+
async _resolveInputRedirect(red, cmdEnv) {
|
|
8253
|
+
if (red.type === '<') {
|
|
8254
|
+
const target = await this.evaluateWord(red.target, cmdEnv);
|
|
8255
|
+
const absTarget = this.resolvePath(target);
|
|
8256
|
+
if (!this.vfs.existsSync(absTarget)) {
|
|
8257
|
+
return { ok: false, error: { code: 1, stdout: '', stderr: `shell: ${target}: No such file or directory\n` } };
|
|
8258
|
+
}
|
|
8259
|
+
try {
|
|
8260
|
+
return { ok: true, stdin: this.vfs.readFileSync(absTarget, 'utf8') };
|
|
8261
|
+
} catch (err) {
|
|
8262
|
+
return { ok: false, error: { code: 1, stdout: '', stderr: `shell: ${target}: ${err.message}\n` } };
|
|
8263
|
+
}
|
|
8264
|
+
}
|
|
8265
|
+
if (red.type === '<<<') {
|
|
8266
|
+
const val = await this.evaluateWord(red.target, cmdEnv);
|
|
8267
|
+
return { ok: true, stdin: val + '\n' };
|
|
8268
|
+
}
|
|
8269
|
+
if (red.type === '<<') {
|
|
8270
|
+
let body = String(red.body || '');
|
|
8271
|
+
if (red.stripTabs) {
|
|
8272
|
+
body = body.replace(/^\t+/gm, '');
|
|
8273
|
+
}
|
|
8274
|
+
if (!red.quoted) {
|
|
8275
|
+
body = await this._expandHeredocBody(body, cmdEnv);
|
|
8276
|
+
}
|
|
8277
|
+
return { ok: true, stdin: body };
|
|
8278
|
+
}
|
|
8279
|
+
return null;
|
|
8280
|
+
}
|
|
8281
|
+
|
|
8282
|
+
_evaluateDoubleBracket(rawArgs) {
|
|
8283
|
+
const closeIdx = rawArgs.lastIndexOf(']]');
|
|
8284
|
+
if (closeIdx === -1) {
|
|
8285
|
+
return { code: 2, stdout: '', stderr: 'shell: [[: missing `]]`\n' };
|
|
8286
|
+
}
|
|
8287
|
+
const tokens = rawArgs.slice(0, closeIdx);
|
|
8288
|
+
let idx = 0;
|
|
8289
|
+
|
|
8290
|
+
const globToRegExp = (pat) => {
|
|
8291
|
+
let re = '^';
|
|
8292
|
+
for (let i = 0; i < pat.length; i++) {
|
|
8293
|
+
const c = pat[i];
|
|
8294
|
+
if (c === '*') re += '.*';
|
|
8295
|
+
else if (c === '?') re += '.';
|
|
8296
|
+
else re += c.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
8297
|
+
}
|
|
8298
|
+
return new RegExp(re + '$');
|
|
8299
|
+
};
|
|
8300
|
+
|
|
8301
|
+
const parseOr = () => {
|
|
8302
|
+
let left = parseAnd();
|
|
8303
|
+
while (tokens[idx] === '||') {
|
|
8304
|
+
idx++;
|
|
8305
|
+
const right = parseAnd();
|
|
8306
|
+
left = left || right;
|
|
8307
|
+
}
|
|
8308
|
+
return left;
|
|
8309
|
+
};
|
|
8310
|
+
|
|
8311
|
+
const parseAnd = () => {
|
|
8312
|
+
let left = parseNot();
|
|
8313
|
+
while (tokens[idx] === '&&') {
|
|
8314
|
+
idx++;
|
|
8315
|
+
const right = parseNot();
|
|
8316
|
+
left = left && right;
|
|
8317
|
+
}
|
|
8318
|
+
return left;
|
|
8319
|
+
};
|
|
8320
|
+
|
|
8321
|
+
const parseNot = () => {
|
|
8322
|
+
if (tokens[idx] === '!') {
|
|
8323
|
+
idx++;
|
|
8324
|
+
return !parseNot();
|
|
8325
|
+
}
|
|
8326
|
+
return parsePrimary();
|
|
8327
|
+
};
|
|
8328
|
+
|
|
8329
|
+
const parsePrimary = () => {
|
|
8330
|
+
if (idx >= tokens.length) return false;
|
|
8331
|
+
if (tokens[idx] === '(') {
|
|
8332
|
+
idx++;
|
|
8333
|
+
const val = parseOr();
|
|
8334
|
+
if (tokens[idx] === ')') idx++;
|
|
8335
|
+
return val;
|
|
8336
|
+
}
|
|
8337
|
+
const unary = tokens[idx];
|
|
8338
|
+
if (/^-(?:z|n|e|f|d|s)$/.test(unary) && idx + 1 < tokens.length) {
|
|
8339
|
+
idx++;
|
|
8340
|
+
const operand = String(tokens[idx++] ?? '');
|
|
8341
|
+
if (unary === '-z') return operand.length === 0;
|
|
8342
|
+
if (unary === '-n') return operand.length > 0;
|
|
8343
|
+
const abs = this.resolvePath(operand);
|
|
8344
|
+
const exists = this.vfs.existsSync(abs);
|
|
8345
|
+
if (unary === '-e') return exists;
|
|
8346
|
+
if (!exists) return false;
|
|
8347
|
+
const st = this.vfs.statSync(abs);
|
|
8348
|
+
if (unary === '-d') return Boolean(st && st.isDirectory());
|
|
8349
|
+
if (unary === '-f') return Boolean(st && !st.isDirectory());
|
|
8350
|
+
if (unary === '-s') return Boolean(st && !st.isDirectory() && st.size > 0);
|
|
8351
|
+
}
|
|
8352
|
+
const left = String(tokens[idx++] ?? '');
|
|
8353
|
+
const op = tokens[idx];
|
|
8354
|
+
if (op && /^(?:==|=|!=|=~|<|>|-eq|-ne|-lt|-le|-gt|-ge)$/.test(op) && idx + 1 < tokens.length) {
|
|
8355
|
+
idx++;
|
|
8356
|
+
const right = String(tokens[idx++] ?? '');
|
|
8357
|
+
if (op === '==' || op === '=') return globToRegExp(right).test(left);
|
|
8358
|
+
if (op === '!=') return !globToRegExp(right).test(left);
|
|
8359
|
+
if (op === '=~') {
|
|
8360
|
+
try { return new RegExp(right).test(left); } catch (err) { _shellLogger.debug('[[ =~ invalid regex', right, err); return false; }
|
|
8361
|
+
}
|
|
8362
|
+
if (op === '<') return left < right;
|
|
8363
|
+
if (op === '>') return left > right;
|
|
8364
|
+
const ln = Number(left) || 0;
|
|
8365
|
+
const rn = Number(right) || 0;
|
|
8366
|
+
if (op === '-eq') return ln === rn;
|
|
8367
|
+
if (op === '-ne') return ln !== rn;
|
|
8368
|
+
if (op === '-lt') return ln < rn;
|
|
8369
|
+
if (op === '-le') return ln <= rn;
|
|
8370
|
+
if (op === '-gt') return ln > rn;
|
|
8371
|
+
if (op === '-ge') return ln >= rn;
|
|
8372
|
+
}
|
|
8373
|
+
return left.length > 0;
|
|
8374
|
+
};
|
|
8375
|
+
|
|
8376
|
+
const ok = parseOr();
|
|
8377
|
+
return { code: ok ? 0 : 1, stdout: '', stderr: '' };
|
|
8378
|
+
}
|
|
8379
|
+
|
|
8054
8380
|
async _executeWithRedirects(redirects, context, execFn) {
|
|
8055
8381
|
if (!redirects || redirects.length === 0) {
|
|
8056
8382
|
return execFn(context);
|
|
@@ -8062,22 +8388,15 @@ var CodeLabLogger = (() => {
|
|
|
8062
8388
|
let effectiveStdin = context.stdin || '';
|
|
8063
8389
|
|
|
8064
8390
|
for (const red of redirects) {
|
|
8065
|
-
if (red.type === '<') {
|
|
8066
|
-
const
|
|
8067
|
-
|
|
8068
|
-
if (
|
|
8069
|
-
return { code: 1, stdout: '', stderr: `shell: ${target}: No such file or directory\n` };
|
|
8070
|
-
}
|
|
8071
|
-
try {
|
|
8072
|
-
effectiveStdin = this.vfs.readFileSync(absTarget, 'utf8');
|
|
8073
|
-
} catch (err) {
|
|
8074
|
-
return { code: 1, stdout: '', stderr: `shell: ${target}: ${err.message}\n` };
|
|
8075
|
-
}
|
|
8391
|
+
if (red.type === '<' || red.type === '<<' || red.type === '<<<') {
|
|
8392
|
+
const inRes = await this._resolveInputRedirect(red, cmdEnv);
|
|
8393
|
+
if (inRes && !inRes.ok) return inRes.error;
|
|
8394
|
+
if (inRes && inRes.ok) effectiveStdin = inRes.stdin;
|
|
8076
8395
|
}
|
|
8077
8396
|
}
|
|
8078
8397
|
|
|
8079
8398
|
for (const red of redirects) {
|
|
8080
|
-
if (red.type === '<') continue;
|
|
8399
|
+
if (red.type === '<' || red.type === '<<' || red.type === '<<<') continue;
|
|
8081
8400
|
if (red.type === '>' || red.type === '>>' || red.type === '&>') {
|
|
8082
8401
|
const target = await this.evaluateWord(red.target, cmdEnv);
|
|
8083
8402
|
const abs = this.resolvePath(target);
|
|
@@ -8586,7 +8905,20 @@ var CodeLabLogger = (() => {
|
|
|
8586
8905
|
args.push(...expanded);
|
|
8587
8906
|
}
|
|
8588
8907
|
|
|
8589
|
-
// 3. Built-in flow control
|
|
8908
|
+
// 3. Built-in flow control & POSIX special builtins
|
|
8909
|
+
if (cmdName === ':') {
|
|
8910
|
+
Object.assign(this.env, cmdEnv);
|
|
8911
|
+
Object.assign(context.env, cmdEnv);
|
|
8912
|
+
return { code: 0, stdout: '', stderr: '' };
|
|
8913
|
+
}
|
|
8914
|
+
if (cmdName === 'exit') {
|
|
8915
|
+
const rawCode = args.length > 0 ? parseInt(args[0], 10) : parseInt(this.env['?'] || '0', 10);
|
|
8916
|
+
const code = Number.isNaN(rawCode) ? 2 : ((rawCode % 256) + 256) % 256;
|
|
8917
|
+
return { code, stdout: '', stderr: '', controlFlow: { type: 'exit', code } };
|
|
8918
|
+
}
|
|
8919
|
+
if (cmdName === '[[') {
|
|
8920
|
+
return this._evaluateDoubleBracket(args);
|
|
8921
|
+
}
|
|
8590
8922
|
if (cmdName === 'break') {
|
|
8591
8923
|
const count = parseInt(args[0], 10) || 1;
|
|
8592
8924
|
return { code: 0, stdout: '', stderr: '', controlFlow: { type: 'break', count } };
|
|
@@ -8604,20 +8936,13 @@ var CodeLabLogger = (() => {
|
|
|
8604
8936
|
return { code: 130, stdout: '', stderr: '', aborted: true };
|
|
8605
8937
|
}
|
|
8606
8938
|
|
|
8607
|
-
// 4. Process input redirection (<, 0
|
|
8939
|
+
// 4. Process input redirection (<, 0<, <<, <<-, <<<)
|
|
8608
8940
|
let effectiveStdin = context.stdin || '';
|
|
8609
8941
|
for (const red of cmdNode.redirects) {
|
|
8610
|
-
if (red.type === '<') {
|
|
8611
|
-
const
|
|
8612
|
-
|
|
8613
|
-
if (
|
|
8614
|
-
return { code: 1, stdout: '', stderr: `shell: ${target}: No such file or directory\n` };
|
|
8615
|
-
}
|
|
8616
|
-
try {
|
|
8617
|
-
effectiveStdin = this.vfs.readFileSync(absTarget, 'utf8');
|
|
8618
|
-
} catch (err) {
|
|
8619
|
-
return { code: 1, stdout: '', stderr: `shell: ${target}: ${err.message}\n` };
|
|
8620
|
-
}
|
|
8942
|
+
if (red.type === '<' || red.type === '<<' || red.type === '<<<') {
|
|
8943
|
+
const inRes = await this._resolveInputRedirect(red, cmdEnv);
|
|
8944
|
+
if (inRes && !inRes.ok) return inRes.error;
|
|
8945
|
+
if (inRes && inRes.ok) effectiveStdin = inRes.stdin;
|
|
8621
8946
|
}
|
|
8622
8947
|
}
|
|
8623
8948
|
|
|
@@ -8626,7 +8951,7 @@ var CodeLabLogger = (() => {
|
|
|
8626
8951
|
let fd2 = { type: 'stderr' };
|
|
8627
8952
|
|
|
8628
8953
|
for (const red of cmdNode.redirects) {
|
|
8629
|
-
if (red.type === '<') continue;
|
|
8954
|
+
if (red.type === '<' || red.type === '<<' || red.type === '<<<') continue;
|
|
8630
8955
|
if (red.type === '>' || red.type === '>>' || red.type === '&>') {
|
|
8631
8956
|
const target = await this.evaluateWord(red.target, cmdEnv);
|
|
8632
8957
|
const abs = this.resolvePath(target);
|