@innovatorved/code-lab 0.5.0 → 0.6.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 +3 -3
- package/CHANGELOG.md +15 -0
- package/README.md +3 -3
- package/dist/code-lab-sql.esm.js +1 -1
- package/dist/code-lab-sql.umd.js +2 -2
- package/dist/code-lab.css +32 -7273
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +4669 -74678
- package/dist/code-lab.js +4655 -74665
- package/dist/code-lab.umd.js +4655 -74665
- package/dist/extensions/cpp.d.ts +2 -2
- package/dist/extensions/cpp.esm.js +1788 -14707
- package/dist/extensions/cpp.js +1788 -14707
- package/dist/extensions/guided-lab.esm.js +2938 -16127
- package/dist/extensions/guided-lab.js +2938 -16127
- package/dist/extensions/python.d.ts +2 -2
- package/dist/extensions/python.esm.js +1769 -14701
- package/dist/extensions/python.js +1769 -14701
- package/dist/index.d.ts +1 -1
- package/dist/preview-sw.js +4 -188
- package/dist/runtime.esm.js +109 -10284
- package/dist/runtime.js +107 -10284
- package/dist/schemas.d.ts +2 -2
- package/dist/schemas.esm.js +2938 -16127
- package/dist/schemas.js +2941 -16130
- package/dist/scm.d.ts +221 -20
- package/dist/shell.esm.js +811 -10002
- package/dist/shell.js +811 -10002
- package/dist/storage.d.ts +9 -0
- package/dist/terminal.esm.js +20 -1347
- package/dist/terminal.js +20 -1347
- package/dist/workbench/command-palette.d.ts +16 -1
- package/dist/workbench/diff-editor.d.ts +27 -1
- package/dist/workbench/icons.d.ts +6 -2
- package/dist/workbench/index.d.ts +32 -0
- package/dist/workbench/intellisense.d.ts +194 -0
- package/dist/workbench/xterm-adapter.d.ts +122 -0
- package/package.json +7 -1
- package/packages/commands/package.json +1 -1
- package/packages/core/package.json +1 -1
- package/packages/editor/package.json +1 -1
- package/packages/fs/package.json +1 -1
- package/packages/preview/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/settings/package.json +1 -1
- package/packages/sql/package.json +1 -1
- package/packages/terminal/package.json +1 -1
- package/packages/ui/package.json +1 -1
- package/packages/ui/src/settings-dialog.ts +36 -24
- package/packages/ui/src/themes.ts +89 -23
- package/src/code-lab.css +1345 -481
- package/src/extensions/cpp.ts +304 -38
- package/src/extensions/python.ts +342 -43
- package/src/index.ts +1 -1
- package/src/runtime.ts +272 -43
- package/src/schemas.ts +2 -2
- package/src/scm.ts +1467 -92
- package/src/shell.ts +1075 -93
- package/src/storage.ts +66 -3
- package/src/terminal.ts +148 -12
- package/src/workbench/command-palette.ts +289 -48
- package/src/workbench/diff-editor.ts +240 -78
- package/src/workbench/icons.ts +250 -53
- package/src/workbench/index.ts +7 -1
- package/src/workbench/intellisense.ts +1859 -0
- package/src/workbench/xterm-adapter.ts +1566 -0
- package/src/workbench.ts +1605 -236
package/src/runtime.ts
CHANGED
|
@@ -1002,21 +1002,59 @@ function __initVirtualRuntime(rootScope) {
|
|
|
1002
1002
|
};
|
|
1003
1003
|
VirtualPath.posix = VirtualPath;
|
|
1004
1004
|
|
|
1005
|
+
let _activeHomeGetter = null;
|
|
1005
1006
|
const VirtualOs = {
|
|
1006
1007
|
tmpdir: () => '/tmp',
|
|
1007
1008
|
EOL: '\n',
|
|
1008
1009
|
platform: () => 'linux',
|
|
1009
1010
|
arch: () => 'x64',
|
|
1010
|
-
homedir: () => '/home/
|
|
1011
|
+
homedir: () => (typeof _activeHomeGetter === 'function' ? _activeHomeGetter() : '/home/codelab'),
|
|
1011
1012
|
hostname: () => 'code-lab-vm',
|
|
1012
1013
|
cpus: () => [{ model: 'Virtual Code-Lab CPU', speed: 3200 }]
|
|
1013
1014
|
};
|
|
1014
1015
|
|
|
1016
|
+
const _replSessions = new Map();
|
|
1017
|
+
|
|
1018
|
+
function transformStatefulReplBody(body, replCtx) {
|
|
1019
|
+
if (!replCtx || typeof replCtx !== 'object') return body;
|
|
1020
|
+
const declared = new Set();
|
|
1021
|
+
let rewritten = body.replace(
|
|
1022
|
+
/(^|\n)\s*const\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=/g,
|
|
1023
|
+
(m, lead, id) => {
|
|
1024
|
+
declared.add(id);
|
|
1025
|
+
return `${lead}let ${id} =`;
|
|
1026
|
+
}
|
|
1027
|
+
);
|
|
1028
|
+
const letVarRegex = /(?:^|\n)\s*(?:let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\b/g;
|
|
1029
|
+
let match;
|
|
1030
|
+
while ((match = letVarRegex.exec(rewritten)) !== null) {
|
|
1031
|
+
declared.add(match[1]);
|
|
1032
|
+
}
|
|
1033
|
+
const fnClassRegex = /(?:^|\n)\s*(?:async\s+)?(?:function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)\b/g;
|
|
1034
|
+
while ((match = fnClassRegex.exec(rewritten)) !== null) {
|
|
1035
|
+
declared.add(match[1]);
|
|
1036
|
+
}
|
|
1037
|
+
const existingKeys = Object.keys(replCtx).filter(
|
|
1038
|
+
(k) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(k) && !declared.has(k)
|
|
1039
|
+
);
|
|
1040
|
+
const preamble = existingKeys
|
|
1041
|
+
.map((k) => `let ${k} = __replCtx[${JSON.stringify(k)}];`)
|
|
1042
|
+
.join('\n');
|
|
1043
|
+
const allSyncKeys = Array.from(new Set([...existingKeys, ...Array.from(declared)]));
|
|
1044
|
+
const epilogue = allSyncKeys
|
|
1045
|
+
.map(
|
|
1046
|
+
(k) =>
|
|
1047
|
+
`try { if (typeof ${k} !== 'undefined') __replCtx[${JSON.stringify(k)}] = ${k}; } catch (_e) { void _e; }`
|
|
1048
|
+
)
|
|
1049
|
+
.join('\n');
|
|
1050
|
+
return `${preamble}\ntry {\n${rewritten}\n} finally {\n${epilogue}\n}`;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1015
1053
|
// =========================================================================
|
|
1016
1054
|
// 5. VIRTUAL IN-MEMORY POSIX FILESYSTEM (node:fs)
|
|
1017
1055
|
// =========================================================================
|
|
1018
1056
|
function createVirtualFs(initialFiles = {}, vfsOptions = {}) {
|
|
1019
|
-
const dirs = new Set(['/', '/tmp', '/workspace', '/home', '/home/user']);
|
|
1057
|
+
const dirs = new Set(['/', '/tmp', '/workspace', '/etc', '/home', '/home/user', '/home/codelab']);
|
|
1020
1058
|
const files = new Map(); // normalizedPath -> { data: Uint8Array, mtimeMs, ctimeMs, ino }
|
|
1021
1059
|
const deletedInspectorCache = new Map(); // normalizedPath -> { data: Uint8Array, mtimeMs, deletedAtMs }
|
|
1022
1060
|
const MAX_DELETED_CACHE_ENTRIES = 50;
|
|
@@ -1095,10 +1133,10 @@ function __initVirtualRuntime(rootScope) {
|
|
|
1095
1133
|
};
|
|
1096
1134
|
}
|
|
1097
1135
|
|
|
1098
|
-
// Seed initial project files into /workspace (preserving system paths like /usr, /tmp, /lib, /include)
|
|
1136
|
+
// Seed initial project files into /workspace (preserving system paths like /usr, /tmp, /lib, /include, /home)
|
|
1099
1137
|
for (const [relPath, content] of Object.entries(initialFiles)) {
|
|
1100
1138
|
const cleanRel = relPath.startsWith('/') ? relPath.slice(1) : relPath;
|
|
1101
|
-
const isSystemPath = /^\/(workspace|usr|tmp|lib|include|etc|bin|dev)(\/|$)/.test(relPath);
|
|
1139
|
+
const isSystemPath = /^\/(workspace|usr|tmp|lib|include|etc|bin|dev|home)(\/|$)/.test(relPath);
|
|
1102
1140
|
let fullPath = isSystemPath
|
|
1103
1141
|
? normPath(relPath)
|
|
1104
1142
|
: normPath(`/workspace/${cleanRel}`);
|
|
@@ -1114,7 +1152,7 @@ function __initVirtualRuntime(rootScope) {
|
|
|
1114
1152
|
ctimeMs: Date.now(),
|
|
1115
1153
|
ino: nextIno++,
|
|
1116
1154
|
mode: 0o100644,
|
|
1117
|
-
isInitialProjectFile: !/^\/(usr|tmp|lib|include|etc|bin|dev)(\/|$)/.test(fullPath)
|
|
1155
|
+
isInitialProjectFile: !/^\/(usr|tmp|lib|include|etc|bin|dev|home)(\/|$)/.test(fullPath)
|
|
1118
1156
|
});
|
|
1119
1157
|
}
|
|
1120
1158
|
|
|
@@ -6487,10 +6525,15 @@ function __initVirtualRuntime(rootScope) {
|
|
|
6487
6525
|
resourceTracker.pid = pid;
|
|
6488
6526
|
|
|
6489
6527
|
const prevCwdGetter = _activeCwdGetter;
|
|
6528
|
+
const prevHomeGetter = _activeHomeGetter;
|
|
6490
6529
|
let currentCwd = (typeof options.cwd === 'string' && options.cwd.trim())
|
|
6491
6530
|
? VirtualPath.resolve('/workspace', options.cwd.trim())
|
|
6492
6531
|
: '/workspace';
|
|
6532
|
+
const currentHome = (options.env && typeof options.env.HOME === 'string' && options.env.HOME.trim())
|
|
6533
|
+
? options.env.HOME.trim()
|
|
6534
|
+
: '/home/codelab';
|
|
6493
6535
|
_activeCwdGetter = () => currentCwd;
|
|
6536
|
+
_activeHomeGetter = () => currentHome;
|
|
6494
6537
|
|
|
6495
6538
|
const vfs = optVfs || createVirtualFs(files, { cwdGetter: () => currentCwd });
|
|
6496
6539
|
const initialOpenFds = typeof vfs._listOpenFds === 'function'
|
|
@@ -6897,9 +6940,26 @@ function __initVirtualRuntime(rootScope) {
|
|
|
6897
6940
|
|
|
6898
6941
|
let syncExecDepth = 0;
|
|
6899
6942
|
|
|
6943
|
+
const stdinStream = new PassThrough();
|
|
6944
|
+
const stdinLinesQueue = [];
|
|
6945
|
+
if (options && typeof options.stdin === 'string' && options.stdin.length > 0) {
|
|
6946
|
+
const normalizedStdin = options.stdin.replace(/\r\n/g, '\n');
|
|
6947
|
+
const parts = normalizedStdin.split('\n');
|
|
6948
|
+
if (parts.length > 0 && parts[parts.length - 1] === '' && normalizedStdin.endsWith('\n')) {
|
|
6949
|
+
parts.pop();
|
|
6950
|
+
}
|
|
6951
|
+
for (const ln of parts) stdinLinesQueue.push(ln);
|
|
6952
|
+
stdinStream.write(options.stdin);
|
|
6953
|
+
if (typeof options.onRequestStdin !== 'function') {
|
|
6954
|
+
stdinStream.end();
|
|
6955
|
+
}
|
|
6956
|
+
} else if (!options || typeof options.onRequestStdin !== 'function') {
|
|
6957
|
+
stdinStream.end();
|
|
6958
|
+
}
|
|
6959
|
+
|
|
6900
6960
|
const sandboxProcess = Object.assign(new EventEmitter(), {
|
|
6901
|
-
env: Object.assign({ NODE_ENV: 'development', PATH: '/usr/local/bin:/usr/bin:/bin', HOME:
|
|
6902
|
-
argv: argv || ['node', entry.startsWith('/') ? entry :
|
|
6961
|
+
env: Object.assign({ NODE_ENV: 'development', PATH: '/usr/local/bin:/usr/bin:/bin', HOME: currentHome }, options.env || {}),
|
|
6962
|
+
argv: argv || ['node', entry.startsWith('/') ? entry : VirtualPath.resolve(currentCwd, entry)],
|
|
6903
6963
|
argv0: 'node',
|
|
6904
6964
|
execArgv: [],
|
|
6905
6965
|
execPath: '/usr/local/bin/node',
|
|
@@ -6949,7 +7009,7 @@ function __initVirtualRuntime(rootScope) {
|
|
|
6949
7009
|
hrtime: hrtimeFn,
|
|
6950
7010
|
stdout: { write: (s) => { emitStdout(String(s)); return true; }, isTTY: false },
|
|
6951
7011
|
stderr: { write: (s) => { emitStderr(String(s)); return true; }, isTTY: false },
|
|
6952
|
-
stdin:
|
|
7012
|
+
stdin: stdinStream,
|
|
6953
7013
|
nextTick: (cb, ...args) => queueMicrotask(() => cb(...args)),
|
|
6954
7014
|
exit: (code = 0) => {
|
|
6955
7015
|
exitCode = Number(code) || 0;
|
|
@@ -7876,20 +7936,97 @@ function __initVirtualRuntime(rootScope) {
|
|
|
7876
7936
|
}
|
|
7877
7937
|
};
|
|
7878
7938
|
|
|
7879
|
-
function
|
|
7939
|
+
function readNextStdinLine(promptText) {
|
|
7940
|
+
if (promptText) {
|
|
7941
|
+
emitStdout(String(promptText));
|
|
7942
|
+
}
|
|
7943
|
+
if (stdinLinesQueue.length > 0) {
|
|
7944
|
+
return Promise.resolve(stdinLinesQueue.shift());
|
|
7945
|
+
}
|
|
7946
|
+
if (options && typeof options.onRequestStdin === 'function' && !hasExited) {
|
|
7947
|
+
const pendingToken = {};
|
|
7948
|
+
resourceTracker.inFlightHttp.add(pendingToken);
|
|
7949
|
+
return Promise.resolve(options.onRequestStdin(''))
|
|
7950
|
+
.then((val) => {
|
|
7951
|
+
resourceTracker.inFlightHttp.delete(pendingToken);
|
|
7952
|
+
if (val === null || val === undefined) return null;
|
|
7953
|
+
const s = String(val);
|
|
7954
|
+
stdinStream.write(s + '\n');
|
|
7955
|
+
return s;
|
|
7956
|
+
})
|
|
7957
|
+
.catch(() => {
|
|
7958
|
+
resourceTracker.inFlightHttp.delete(pendingToken);
|
|
7959
|
+
return null;
|
|
7960
|
+
});
|
|
7961
|
+
}
|
|
7962
|
+
return Promise.resolve(null);
|
|
7963
|
+
}
|
|
7964
|
+
|
|
7965
|
+
function makeReadlineInterface(rlOpts) {
|
|
7880
7966
|
const iface = new EventEmitter();
|
|
7967
|
+
let closed = false;
|
|
7968
|
+
let promptStr = (rlOpts && typeof rlOpts.prompt === 'string') ? rlOpts.prompt : '> ';
|
|
7881
7969
|
iface.terminal = false;
|
|
7882
7970
|
iface.line = '';
|
|
7883
7971
|
iface.cursor = 0;
|
|
7884
|
-
iface.question = (query,
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7972
|
+
iface.question = (query, optionsOrCb, maybeCb) => {
|
|
7973
|
+
const cb = typeof optionsOrCb === 'function' ? optionsOrCb : maybeCb;
|
|
7974
|
+
readNextStdinLine(query).then((ans) => {
|
|
7975
|
+
const resolvedAns = ans === null ? '' : ans;
|
|
7976
|
+
iface.line = resolvedAns;
|
|
7977
|
+
if (typeof cb === 'function' && !closed && !hasExited) {
|
|
7978
|
+
cb(resolvedAns);
|
|
7979
|
+
}
|
|
7980
|
+
});
|
|
7981
|
+
};
|
|
7982
|
+
iface.prompt = () => {
|
|
7983
|
+
emitStdout(promptStr);
|
|
7984
|
+
};
|
|
7985
|
+
iface.setPrompt = (p) => {
|
|
7986
|
+
promptStr = String(p ?? '');
|
|
7987
|
+
};
|
|
7988
|
+
iface.getPrompt = () => promptStr;
|
|
7989
|
+
iface.write = (d) => {
|
|
7990
|
+
if (d !== undefined && d !== null) emitStdout(String(d));
|
|
7991
|
+
};
|
|
7889
7992
|
iface.pause = () => iface;
|
|
7890
|
-
iface.resume = () =>
|
|
7891
|
-
|
|
7892
|
-
|
|
7993
|
+
iface.resume = () => {
|
|
7994
|
+
queueMicrotask(async () => {
|
|
7995
|
+
while (!closed && !hasExited && stdinLinesQueue.length > 0) {
|
|
7996
|
+
const ln = stdinLinesQueue.shift();
|
|
7997
|
+
iface.line = ln;
|
|
7998
|
+
iface.emit('line', ln);
|
|
7999
|
+
}
|
|
8000
|
+
});
|
|
8001
|
+
return iface;
|
|
8002
|
+
};
|
|
8003
|
+
iface.close = () => {
|
|
8004
|
+
if (!closed) {
|
|
8005
|
+
closed = true;
|
|
8006
|
+
queueMicrotask(() => iface.emit('close'));
|
|
8007
|
+
}
|
|
8008
|
+
return iface;
|
|
8009
|
+
};
|
|
8010
|
+
iface[Symbol.asyncIterator] = async function* () {
|
|
8011
|
+
while (!closed && !hasExited) {
|
|
8012
|
+
const ln = await readNextStdinLine('');
|
|
8013
|
+
if (ln === null) break;
|
|
8014
|
+
iface.line = ln;
|
|
8015
|
+
yield ln;
|
|
8016
|
+
}
|
|
8017
|
+
};
|
|
8018
|
+
queueMicrotask(() => {
|
|
8019
|
+
if (iface.listenerCount('line') > 0 && stdinLinesQueue.length > 0) {
|
|
8020
|
+
while (!closed && !hasExited && stdinLinesQueue.length > 0) {
|
|
8021
|
+
const ln = stdinLinesQueue.shift();
|
|
8022
|
+
iface.line = ln;
|
|
8023
|
+
iface.emit('line', ln);
|
|
8024
|
+
}
|
|
8025
|
+
if (!options || typeof options.onRequestStdin !== 'function') {
|
|
8026
|
+
iface.close();
|
|
8027
|
+
}
|
|
8028
|
+
}
|
|
8029
|
+
});
|
|
7893
8030
|
return iface;
|
|
7894
8031
|
}
|
|
7895
8032
|
const VirtualReadline = {
|
|
@@ -7902,9 +8039,10 @@ function __initVirtualRuntime(rootScope) {
|
|
|
7902
8039
|
emitKeypressEvents: () => {}
|
|
7903
8040
|
};
|
|
7904
8041
|
const VirtualReadlinePromises = {
|
|
7905
|
-
createInterface: () => {
|
|
7906
|
-
const iface = makeReadlineInterface();
|
|
7907
|
-
iface.question = () =>
|
|
8042
|
+
createInterface: (rlOpts) => {
|
|
8043
|
+
const iface = makeReadlineInterface(rlOpts);
|
|
8044
|
+
iface.question = (query) =>
|
|
8045
|
+
readNextStdinLine(query).then((ans) => (ans === null ? '' : ans));
|
|
7908
8046
|
return iface;
|
|
7909
8047
|
},
|
|
7910
8048
|
Interface: class ReadlinePromisesInterface extends EventEmitter {}
|
|
@@ -8708,6 +8846,15 @@ function __initVirtualRuntime(rootScope) {
|
|
|
8708
8846
|
body = transpiledRepl;
|
|
8709
8847
|
}
|
|
8710
8848
|
}
|
|
8849
|
+
let replCtx = null;
|
|
8850
|
+
if (options && typeof options.replSessionId === 'string' && options.replSessionId) {
|
|
8851
|
+
replCtx = _replSessions.get(options.replSessionId);
|
|
8852
|
+
if (!replCtx) {
|
|
8853
|
+
replCtx = Object.create(null);
|
|
8854
|
+
_replSessions.set(options.replSessionId, replCtx);
|
|
8855
|
+
}
|
|
8856
|
+
body = transformStatefulReplBody(body, replCtx);
|
|
8857
|
+
}
|
|
8711
8858
|
const replFn = compileFunction(
|
|
8712
8859
|
[
|
|
8713
8860
|
'require',
|
|
@@ -8721,7 +8868,8 @@ function __initVirtualRuntime(rootScope) {
|
|
|
8721
8868
|
'setImmediate',
|
|
8722
8869
|
'clearImmediate',
|
|
8723
8870
|
'Bun',
|
|
8724
|
-
'fetch'
|
|
8871
|
+
'fetch',
|
|
8872
|
+
'__replCtx'
|
|
8725
8873
|
],
|
|
8726
8874
|
`return (async () => {\n${body}\n})();`
|
|
8727
8875
|
);
|
|
@@ -8738,14 +8886,21 @@ function __initVirtualRuntime(rootScope) {
|
|
|
8738
8886
|
sandboxSetImmediate,
|
|
8739
8887
|
sandboxClearImmediate,
|
|
8740
8888
|
BunObj,
|
|
8741
|
-
sandboxGlobal.fetch
|
|
8889
|
+
sandboxGlobal.fetch,
|
|
8890
|
+
replCtx || Object.create(null)
|
|
8742
8891
|
)
|
|
8743
8892
|
);
|
|
8893
|
+
if (replCtx && replValue !== undefined) {
|
|
8894
|
+
replCtx._ = replValue;
|
|
8895
|
+
}
|
|
8744
8896
|
if (!hasExited && replValue !== undefined && options.printReplResult !== false) {
|
|
8745
8897
|
emitStdout(formatConsoleArg(replValue) + '\n');
|
|
8746
8898
|
}
|
|
8747
8899
|
} else {
|
|
8748
|
-
|
|
8900
|
+
const resolvedRelEntry = entry.startsWith('/') ? entry : VirtualPath.resolve(currentCwd, entry);
|
|
8901
|
+
let entryAbs = vfs.existsSync(resolvedRelEntry)
|
|
8902
|
+
? resolvedRelEntry
|
|
8903
|
+
: (vfs.existsSync(entry) ? entry : `/workspace/${entry.replace(/^\/+/, '')}`);
|
|
8749
8904
|
if (!vfs.existsSync(entryAbs)) {
|
|
8750
8905
|
const alt = `/workspace/src/${entry.replace(/^\/+/, '')}`;
|
|
8751
8906
|
if (vfs.existsSync(alt)) entryAbs = alt;
|
|
@@ -8924,6 +9079,7 @@ function __initVirtualRuntime(rootScope) {
|
|
|
8924
9079
|
}
|
|
8925
9080
|
}
|
|
8926
9081
|
_activeCwdGetter = prevCwdGetter;
|
|
9082
|
+
_activeHomeGetter = prevHomeGetter;
|
|
8927
9083
|
}
|
|
8928
9084
|
|
|
8929
9085
|
const failedTests = testResults.filter((t) => !t.passed).length;
|
|
@@ -9710,22 +9866,54 @@ function __initVirtualRuntime(rootScope) {
|
|
|
9710
9866
|
createVirtualPortTable,
|
|
9711
9867
|
createVirtualWasi,
|
|
9712
9868
|
executeWasiModule,
|
|
9713
|
-
executeInVirtualRuntime
|
|
9869
|
+
executeInVirtualRuntime,
|
|
9870
|
+
clearReplSession(sessionId) {
|
|
9871
|
+
if (sessionId) _replSessions.delete(sessionId);
|
|
9872
|
+
else _replSessions.clear();
|
|
9873
|
+
}
|
|
9714
9874
|
};
|
|
9715
9875
|
|
|
9716
9876
|
}
|
|
9717
9877
|
|
|
9718
9878
|
function __workerMessageLoop(workerScope) {
|
|
9719
9879
|
const runtime = workerScope.__virtualRuntime;
|
|
9880
|
+
const pendingStdinResolvers = new Map();
|
|
9881
|
+
let stdinReqSeq = 1;
|
|
9882
|
+
|
|
9720
9883
|
workerScope.onmessage = async function (event) {
|
|
9721
9884
|
const msg = event.data || {};
|
|
9722
9885
|
const { requestId, type, payload = {} } = msg;
|
|
9886
|
+
if (type === 'clear-repl') {
|
|
9887
|
+
if (runtime && typeof runtime.clearReplSession === 'function') {
|
|
9888
|
+
runtime.clearReplSession(msg.replSessionId);
|
|
9889
|
+
}
|
|
9890
|
+
return;
|
|
9891
|
+
}
|
|
9892
|
+
if (type === 'stdin-reply') {
|
|
9893
|
+
const resolver = pendingStdinResolvers.get(msg.stdinId);
|
|
9894
|
+
if (resolver) {
|
|
9895
|
+
pendingStdinResolvers.delete(msg.stdinId);
|
|
9896
|
+
resolver(msg.value);
|
|
9897
|
+
}
|
|
9898
|
+
return;
|
|
9899
|
+
}
|
|
9723
9900
|
if (type !== 'execute') return;
|
|
9724
9901
|
workerScope.postMessage({ requestId, type: 'started' });
|
|
9725
9902
|
try {
|
|
9726
9903
|
const result = await runtime.executeInVirtualRuntime({
|
|
9727
9904
|
...payload,
|
|
9728
9905
|
_captureVfsDiff: true,
|
|
9906
|
+
...(payload.interactiveStdin
|
|
9907
|
+
? {
|
|
9908
|
+
onRequestStdin(prompt) {
|
|
9909
|
+
const stdinId = `${requestId}_${stdinReqSeq++}`;
|
|
9910
|
+
return new Promise((resolveStdin) => {
|
|
9911
|
+
pendingStdinResolvers.set(stdinId, resolveStdin);
|
|
9912
|
+
workerScope.postMessage({ requestId, type: 'stdin-request', stdinId, prompt });
|
|
9913
|
+
});
|
|
9914
|
+
}
|
|
9915
|
+
}
|
|
9916
|
+
: {}),
|
|
9729
9917
|
onStdout(text) {
|
|
9730
9918
|
workerScope.postMessage({ requestId, type: 'stdout', text });
|
|
9731
9919
|
},
|
|
@@ -9782,6 +9970,9 @@ function _ensureWarmWorker() {
|
|
|
9782
9970
|
}
|
|
9783
9971
|
if (_warmWorker) _destroyWarmWorker();
|
|
9784
9972
|
_warmWorker = new Worker(_ensureWorkerUrl());
|
|
9973
|
+
if (_warmWorker && typeof _warmWorker.unref === 'function') {
|
|
9974
|
+
_warmWorker.unref();
|
|
9975
|
+
}
|
|
9785
9976
|
return _warmWorker;
|
|
9786
9977
|
}
|
|
9787
9978
|
|
|
@@ -9861,6 +10052,7 @@ function _extractWorkerFilesFromVfs(vfs) {
|
|
|
9861
10052
|
};
|
|
9862
10053
|
walk('/workspace');
|
|
9863
10054
|
walk('/tmp');
|
|
10055
|
+
walk('/home');
|
|
9864
10056
|
}
|
|
9865
10057
|
} catch (err) {
|
|
9866
10058
|
_hostLogger.debug('_extractWorkerFilesFromVfs failed', err);
|
|
@@ -9960,6 +10152,9 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
|
|
|
9960
10152
|
worker = new Worker(_ensureWorkerUrl());
|
|
9961
10153
|
isWarmWorker = false;
|
|
9962
10154
|
}
|
|
10155
|
+
if (worker && typeof worker.ref === 'function') {
|
|
10156
|
+
worker.ref();
|
|
10157
|
+
}
|
|
9963
10158
|
} catch (_) {
|
|
9964
10159
|
if (isWarmWorker) _warmWorkerBusy = false;
|
|
9965
10160
|
resolve(_hostRuntime.executeInVirtualRuntime(options));
|
|
@@ -9998,6 +10193,9 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
|
|
|
9998
10193
|
if (_warmWorker) {
|
|
9999
10194
|
_warmWorker.onmessage = null;
|
|
10000
10195
|
_warmWorker.onerror = null;
|
|
10196
|
+
if (typeof _warmWorker.unref === 'function') {
|
|
10197
|
+
_warmWorker.unref();
|
|
10198
|
+
}
|
|
10001
10199
|
}
|
|
10002
10200
|
}
|
|
10003
10201
|
} else {
|
|
@@ -10005,25 +10203,30 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
|
|
|
10005
10203
|
}
|
|
10006
10204
|
}
|
|
10007
10205
|
|
|
10008
|
-
|
|
10009
|
-
|
|
10010
|
-
|
|
10011
|
-
|
|
10012
|
-
|
|
10013
|
-
|
|
10014
|
-
|
|
10015
|
-
|
|
10016
|
-
|
|
10017
|
-
|
|
10018
|
-
|
|
10019
|
-
|
|
10020
|
-
|
|
10021
|
-
|
|
10022
|
-
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
|
|
10206
|
+
let timer = null;
|
|
10207
|
+
const armWatchdog = () => {
|
|
10208
|
+
if (timer) clearTimeout(timer);
|
|
10209
|
+
timer = setTimeout(() => {
|
|
10210
|
+
if (settled) return;
|
|
10211
|
+
settled = true;
|
|
10212
|
+
releaseWorker(true);
|
|
10213
|
+
const timeoutMsg = `Execution timed out after ${timeoutMs}ms (infinite loop or hung timer terminated).\n`;
|
|
10214
|
+
resolve({
|
|
10215
|
+
ok: false,
|
|
10216
|
+
timedOut: true,
|
|
10217
|
+
exitCode: 124,
|
|
10218
|
+
durationMs: timeoutMs,
|
|
10219
|
+
stdout: streamedStdoutChunks.join(''),
|
|
10220
|
+
stderr: streamedStderrChunks.join('') + timeoutMsg,
|
|
10221
|
+
testResults: streamedTestResults.slice(),
|
|
10222
|
+
testSummary: buildTestSummary(),
|
|
10223
|
+
fsSnapshot: [],
|
|
10224
|
+
httpTrace: [],
|
|
10225
|
+
error: { message: `Execution timed out after ${timeoutMs}ms` }
|
|
10226
|
+
});
|
|
10227
|
+
}, timeoutMs + 500);
|
|
10228
|
+
};
|
|
10229
|
+
armWatchdog();
|
|
10027
10230
|
|
|
10028
10231
|
_activeWorkerJobs.set(requestId, {
|
|
10029
10232
|
requestId,
|
|
@@ -10076,6 +10279,30 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
|
|
|
10076
10279
|
userCodeStarted = true;
|
|
10077
10280
|
if (typeof msg.text === 'string') streamedStderrChunks.push(msg.text);
|
|
10078
10281
|
if (typeof options.onStderr === 'function') options.onStderr(msg.text);
|
|
10282
|
+
} else if (msg.type === 'stdin-request') {
|
|
10283
|
+
userCodeStarted = true;
|
|
10284
|
+
if (timer) {
|
|
10285
|
+
clearTimeout(timer);
|
|
10286
|
+
timer = null;
|
|
10287
|
+
}
|
|
10288
|
+
if (typeof options.onRequestStdin === 'function') {
|
|
10289
|
+
Promise.resolve(options.onRequestStdin(msg.prompt || ''))
|
|
10290
|
+
.then((val) => {
|
|
10291
|
+
if (!settled) {
|
|
10292
|
+
armWatchdog();
|
|
10293
|
+
worker.postMessage({ requestId, type: 'stdin-reply', stdinId: msg.stdinId, value: val });
|
|
10294
|
+
}
|
|
10295
|
+
})
|
|
10296
|
+
.catch(() => {
|
|
10297
|
+
if (!settled) {
|
|
10298
|
+
armWatchdog();
|
|
10299
|
+
worker.postMessage({ requestId, type: 'stdin-reply', stdinId: msg.stdinId, value: null });
|
|
10300
|
+
}
|
|
10301
|
+
});
|
|
10302
|
+
} else {
|
|
10303
|
+
armWatchdog();
|
|
10304
|
+
worker.postMessage({ requestId, type: 'stdin-reply', stdinId: msg.stdinId, value: null });
|
|
10305
|
+
}
|
|
10079
10306
|
} else if (msg.type === 'test-result') {
|
|
10080
10307
|
userCodeStarted = true;
|
|
10081
10308
|
if (msg.testResult) streamedTestResults.push(msg.testResult);
|
|
@@ -10149,6 +10376,8 @@ _hostRuntime.executeInWorker = async function executeInWorker(options = {}) {
|
|
|
10149
10376
|
entry: options.entry,
|
|
10150
10377
|
mode: options.mode,
|
|
10151
10378
|
replCode: options.replCode,
|
|
10379
|
+
replSessionId: options.replSessionId,
|
|
10380
|
+
interactiveStdin: typeof options.onRequestStdin === 'function',
|
|
10152
10381
|
testFilter: options.testFilter,
|
|
10153
10382
|
timeoutMs: options.timeoutMs,
|
|
10154
10383
|
maxOutputBytes: options.maxOutputBytes,
|
package/src/schemas.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as z from 'zod';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Zod Schemas and Inferred TypeScript Types for code-lab v0.
|
|
4
|
+
* Zod Schemas and Inferred TypeScript Types for code-lab v0.6.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// ── 1. Guided Step ──────────────────────────────────────────────────────────
|