wasm-idle 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/README.md +267 -112
  2. package/dist/container/bash-profile.d.ts +80 -0
  3. package/dist/container/bash-profile.js +328 -0
  4. package/dist/container/binding.d.ts +39 -0
  5. package/dist/container/binding.js +331 -0
  6. package/dist/container/clang-runtime.d.ts +42 -0
  7. package/dist/container/clang-runtime.js +561 -0
  8. package/dist/container/client.d.ts +14 -0
  9. package/dist/container/client.js +185 -0
  10. package/dist/container/explorer.d.ts +31 -0
  11. package/dist/container/explorer.js +112 -0
  12. package/dist/container/index.d.ts +11 -0
  13. package/dist/container/index.js +11 -0
  14. package/dist/container/owner-worker.d.ts +19 -0
  15. package/dist/container/owner-worker.js +464 -0
  16. package/dist/container/protocol.d.ts +84 -0
  17. package/dist/container/protocol.js +28 -0
  18. package/dist/container/runtime-adapter.d.ts +75 -0
  19. package/dist/container/runtime-adapter.js +537 -0
  20. package/dist/container/shell-control.d.ts +49 -0
  21. package/dist/container/shell-control.js +360 -0
  22. package/dist/container/workspace.d.ts +12 -0
  23. package/dist/container/workspace.js +29 -0
  24. package/dist/index.d.ts +1 -1
  25. package/dist/playground/assetBridge.js +111 -33
  26. package/dist/playground/assets.d.ts +10 -2
  27. package/dist/playground/c3.js +22 -0
  28. package/dist/playground/c3Memory.d.ts +19 -0
  29. package/dist/playground/c3Memory.js +117 -0
  30. package/dist/playground/cachedClang.js +143 -34
  31. package/dist/playground/clang.d.ts +5 -1
  32. package/dist/playground/clang.js +61 -5
  33. package/dist/playground/clangAssetIntegrity.js +6 -6
  34. package/dist/playground/clangWorkerProtocol.d.ts +12 -1
  35. package/dist/playground/cobol.d.ts +3 -0
  36. package/dist/playground/cobol.js +10 -1
  37. package/dist/playground/commonlispAssets.d.ts +2 -2
  38. package/dist/playground/compiledArtifactCache.d.ts +3 -1
  39. package/dist/playground/compiledArtifactCache.js +31 -5
  40. package/dist/playground/compiledLldb.d.ts +41 -0
  41. package/dist/playground/compiledLldb.js +167 -0
  42. package/dist/playground/d.d.ts +10 -2
  43. package/dist/playground/d.js +161 -14
  44. package/dist/playground/debugDeadline.d.ts +12 -0
  45. package/dist/playground/debugDeadline.js +34 -0
  46. package/dist/playground/debugMailbox.d.ts +12 -0
  47. package/dist/playground/debugMailbox.js +77 -0
  48. package/dist/playground/dotnet.js +6 -8
  49. package/dist/playground/fortran.d.ts +3 -0
  50. package/dist/playground/fortran.js +10 -1
  51. package/dist/playground/go.js +23 -7
  52. package/dist/playground/goDebugInstrumentation.js +207 -97
  53. package/dist/playground/java-debug-FMHDKUN6.js +124 -0
  54. package/dist/playground/java-debug-notices.txt +492 -0
  55. package/dist/playground/java.d.ts +17 -1
  56. package/dist/playground/java.js +162 -5
  57. package/dist/playground/javaDebug.d.ts +62 -0
  58. package/dist/playground/javaDebug.js +305 -0
  59. package/dist/playground/javaDebugBridge.d.ts +6 -0
  60. package/dist/playground/javaDebugBridge.js +250 -0
  61. package/dist/playground/javaDebugSource.d.ts +9 -0
  62. package/dist/playground/javaDebugSource.js +4 -0
  63. package/dist/playground/javaRuntimeErrors.d.ts +9 -0
  64. package/dist/playground/javaRuntimeErrors.js +93 -0
  65. package/dist/playground/lean4Assets.d.ts +1 -25
  66. package/dist/playground/lean4Assets.js +2 -123
  67. package/dist/playground/lfortran.js +10 -0
  68. package/dist/playground/lfortranAssets.d.ts +2 -2
  69. package/dist/playground/lldbSession.d.ts +23 -2
  70. package/dist/playground/lldbSession.js +278 -58
  71. package/dist/playground/lldbSourcePath.d.ts +2 -0
  72. package/dist/playground/lldbSourcePath.js +9 -0
  73. package/dist/playground/lua.d.ts +20 -1
  74. package/dist/playground/lua.js +190 -8
  75. package/dist/playground/luaDebug.d.ts +1 -0
  76. package/dist/playground/luaDebug.js +1 -0
  77. package/dist/playground/nim.d.ts +1 -0
  78. package/dist/playground/nim.js +30 -0
  79. package/dist/playground/objectivec.d.ts +10 -6
  80. package/dist/playground/objectivec.js +85 -10
  81. package/dist/playground/options.d.ts +12 -4
  82. package/dist/playground/python.d.ts +8 -1
  83. package/dist/playground/python.js +89 -6
  84. package/dist/playground/ruby.d.ts +10 -1
  85. package/dist/playground/ruby.js +66 -1
  86. package/dist/playground/rubyDebug.d.ts +21 -0
  87. package/dist/playground/rubyDebug.js +128 -0
  88. package/dist/playground/runtimeAssetCache.d.ts +1 -32
  89. package/dist/playground/runtimeAssetCache.js +1 -193
  90. package/dist/playground/runtimeSession.d.ts +2 -2
  91. package/dist/playground/runtimeSession.js +11 -11
  92. package/dist/playground/rust.d.ts +10 -0
  93. package/dist/playground/rust.js +230 -51
  94. package/dist/playground/sandbox.d.ts +8 -1
  95. package/dist/playground/staticStdinRing.d.ts +2 -1
  96. package/dist/playground/staticStdinRing.js +21 -10
  97. package/dist/playground/staticWorkerRuntime.d.ts +15 -1
  98. package/dist/playground/staticWorkerRuntime.js +127 -19
  99. package/dist/playground/stdinBuffer.d.ts +1 -1
  100. package/dist/playground/stdinBuffer.js +19 -2
  101. package/dist/playground/tinygo.d.ts +3 -0
  102. package/dist/playground/tinygo.js +88 -6
  103. package/dist/playground/typescript.js +8 -0
  104. package/dist/playground/v.d.ts +6 -2
  105. package/dist/playground/v.js +76 -13
  106. package/dist/playground/wasmAwkVersion.d.ts +13 -13
  107. package/dist/playground/wasmAwkVersion.js +4 -4
  108. package/dist/playground/wasmBqnVersion.d.ts +2 -2
  109. package/dist/playground/wasmBqnVersion.js +2 -2
  110. package/dist/playground/wasmC3Version.d.ts +2 -2
  111. package/dist/playground/wasmC3Version.js +2 -2
  112. package/dist/playground/wasmClojureScriptVersion.d.ts +2 -2
  113. package/dist/playground/wasmClojureScriptVersion.js +2 -2
  114. package/dist/playground/wasmCommonLispVersion.d.ts +2 -2
  115. package/dist/playground/wasmCommonLispVersion.js +2 -2
  116. package/dist/playground/wasmDIntegrity.d.ts +5 -5
  117. package/dist/playground/wasmDIntegrity.js +5 -5
  118. package/dist/playground/wasmDVersion.d.ts +16 -1
  119. package/dist/playground/wasmDVersion.js +16 -1
  120. package/dist/playground/wasmDebugVersion.d.ts +1 -1
  121. package/dist/playground/wasmDebugVersion.js +1 -1
  122. package/dist/playground/wasmForthVersion.d.ts +2 -2
  123. package/dist/playground/wasmForthVersion.js +2 -2
  124. package/dist/playground/wasmGleamVersion.d.ts +2 -2
  125. package/dist/playground/wasmGleamVersion.js +2 -2
  126. package/dist/playground/wasmGrainVersion.d.ts +2 -2
  127. package/dist/playground/wasmGrainVersion.js +2 -2
  128. package/dist/playground/wasmJVersion.d.ts +2 -2
  129. package/dist/playground/wasmJVersion.js +2 -2
  130. package/dist/playground/wasmJanetVersion.js +2 -2
  131. package/dist/playground/wasmJuliaVersion.js +2 -2
  132. package/dist/playground/wasmLean4Version.d.ts +1 -110
  133. package/dist/playground/wasmLean4Version.js +2 -111
  134. package/dist/playground/wasmLfortranVersion.d.ts +2 -2
  135. package/dist/playground/wasmLfortranVersion.js +2 -2
  136. package/dist/playground/wasmLuaVersion.d.ts +1 -1
  137. package/dist/playground/wasmLuaVersion.js +1 -1
  138. package/dist/playground/wasmNimVersion.d.ts +9 -9
  139. package/dist/playground/wasmNimVersion.js +6 -6
  140. package/dist/playground/wasmOcamlVersion.d.ts +2 -2
  141. package/dist/playground/wasmOcamlVersion.js +1 -1
  142. package/dist/playground/wasmPascalVersion.js +2 -2
  143. package/dist/playground/wasmPerlVersion.js +2 -2
  144. package/dist/playground/wasmPrologVersion.d.ts +2 -2
  145. package/dist/playground/wasmPrologVersion.js +2 -2
  146. package/dist/playground/wasmReScriptVersion.d.ts +2 -2
  147. package/dist/playground/wasmReScriptVersion.js +2 -2
  148. package/dist/playground/wasmRustVersion.d.ts +26 -38
  149. package/dist/playground/wasmRustVersion.js +25 -40
  150. package/dist/playground/wasmTclVersion.d.ts +4 -4
  151. package/dist/playground/wasmTclVersion.js +2 -2
  152. package/dist/playground/wasmTinyGoVersion.d.ts +14 -14
  153. package/dist/playground/wasmTinyGoVersion.js +14 -14
  154. package/dist/playground/wasmTypeScriptVersion.d.ts +5 -5
  155. package/dist/playground/wasmTypeScriptVersion.js +5 -5
  156. package/dist/playground/worker/cachedClangCompile.js +52 -4
  157. package/dist/playground/worker/cachedClangExecute.js +6 -5
  158. package/dist/playground/worker/clang.js +33 -11
  159. package/dist/playground/worker/cobol.js +3 -3
  160. package/dist/playground/worker/d.js +63 -7
  161. package/dist/playground/worker/fortran.js +3 -3
  162. package/dist/playground/worker/go.js +16 -5
  163. package/dist/playground/worker/haskell.js +10 -7
  164. package/dist/playground/worker/java.js +263 -45
  165. package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
  166. package/dist/playground/worker/javaDebugEvaluator.js +44 -0
  167. package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
  168. package/dist/playground/worker/javaDebugRuntime.js +315 -0
  169. package/dist/playground/worker/javaOutput.d.ts +11 -0
  170. package/dist/playground/worker/javaOutput.js +54 -0
  171. package/dist/playground/worker/lua.js +15 -3
  172. package/dist/playground/worker/php.js +15 -9
  173. package/dist/playground/worker/python.js +102 -30
  174. package/dist/playground/worker/pythonExecution.js +17 -1
  175. package/dist/playground/worker/pythonWorkspaceFiles.d.ts +6 -0
  176. package/dist/playground/worker/pythonWorkspaceFiles.js +26 -0
  177. package/dist/playground/worker/pythonWorkspaceImports.d.ts +4 -0
  178. package/dist/playground/worker/pythonWorkspaceImports.js +129 -0
  179. package/dist/playground/worker/r.js +13 -6
  180. package/dist/playground/worker/ruby.js +13 -0
  181. package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
  182. package/dist/playground/worker/rubyDebugPreview.js +80 -0
  183. package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
  184. package/dist/playground/worker/rubyTracepoint.js +162 -0
  185. package/dist/playground/worker/rust.js +38 -3
  186. package/dist/playground/worker/sqlite.js +4 -3
  187. package/dist/playground/worker/tinygo.js +11 -3
  188. package/dist/playground/worker/typescript.js +2 -3
  189. package/dist/playground/worker/v.js +32 -7
  190. package/dist/playground/worker/wat.js +2 -3
  191. package/dist/playground/worker/zig.js +20 -6
  192. package/dist/playground/workerSession.d.ts +1 -28
  193. package/dist/playground/workerSession.js +1 -164
  194. package/dist/playground/zig.js +4 -0
  195. package/package.json +66 -15
  196. package/dist/playground/worker/python.runtime.cases.d.ts +0 -1
  197. package/dist/playground/worker/python.runtime.cases.js +0 -374
@@ -0,0 +1,80 @@
1
+ import { type Container, type ContainerOptions, type SnapshotEntry, type HostCommandInvocation, type HostCommandRecord, type HostCommandRoute } from '@wasm-idle/container';
2
+ import { type WasixAssetReference, type WasixSdk, type WasixShellOptions, type WasixShellSession, type WasixWorkerGroup } from '@wasm-idle/container/adapters/wasix';
3
+ export declare const BASH_BIN = "/usr/local/bin";
4
+ export declare const BASH_SYSROOT = "/usr/share/wasm-sysroot";
5
+ export declare const C_SYSROOT = "/usr/share/wasm-sysroot-c";
6
+ /** Expose the verified legacy sysroot through the canonical driver's automatic search paths. */
7
+ export declare function withCanonicalWasiPaths(entries: readonly Omit<SnapshotEntry, 'inode'>[]): readonly Omit<SnapshotEntry, "inode">[];
8
+ /** Pinned assets and worker URLs selected by trusted application code. */
9
+ export interface BashProfileConfiguration {
10
+ manifest: string;
11
+ manifestSha256: string;
12
+ assetURLs: readonly string[];
13
+ sdkUrl: string;
14
+ sdkWorkerUrl: string;
15
+ liveWorkerUrl: string;
16
+ clangWorkerUrl: string;
17
+ sdkAsset?: WasixAssetReference;
18
+ shellAsset?: WasixAssetReference;
19
+ bashWasmSha256: string;
20
+ memory: WasixShellOptions['memory'];
21
+ clangSha256: string;
22
+ linkerSha256: string;
23
+ cacheNamespace: string;
24
+ commandTimeoutMs?: number;
25
+ maxWorkers?: number;
26
+ clangFilesystem?: string;
27
+ /** Requires a matching host Worker with module reuse services. */
28
+ clangModuleServices?: boolean;
29
+ sysrootProfile?: 'full' | 'c-base-v1';
30
+ sysrootLayers?: {
31
+ schemaVersion: 1;
32
+ basePackage: 'llvm-sysroot-c';
33
+ cxxPackage: 'llvm-sysroot-cxx';
34
+ full: {
35
+ sha256: string;
36
+ bytes: number;
37
+ };
38
+ };
39
+ }
40
+ export interface BashProfileOptions {
41
+ config: BashProfileConfiguration;
42
+ sdk: WasixSdk;
43
+ /** The injecting host retains the lifetime of this persistence workspace. */
44
+ workspace?: ContainerOptions['workspace'];
45
+ fetch?: typeof globalThis.fetch;
46
+ onRecord?: (record: HostCommandRecord) => void;
47
+ onInvocation?: (invocation: HostCommandInvocation) => void;
48
+ adapters?: ContainerOptions['adapters'];
49
+ commands?: ContainerOptions['commands'];
50
+ workerGroup?: WasixWorkerGroup;
51
+ /** Registered BusyBox commands chosen by the application's pinned distribution. */
52
+ shellCommands?: readonly string[];
53
+ shellRoutes?: Readonly<Record<string, HostCommandRoute>>;
54
+ }
55
+ /** Compose verified USTAR layers without changing retained header or file bytes. */
56
+ export declare function composeSysrootLayers(base: Uint8Array, cxx: Uint8Array): Uint8Array<ArrayBuffer>;
57
+ /** A shared Bash/Clang owner. Importing this module does not load any runtime assets. */
58
+ export declare function createBashProfile({ config, sdk, workspace, fetch: fetcher, onRecord, onInvocation, adapters, commands, workerGroup, shellCommands, shellRoutes }: BashProfileOptions): Promise<Readonly<{
59
+ container: Container;
60
+ manager: import("@wasm-idle/container").ContainerPackageManager;
61
+ shellAssets: import("@wasm-idle/container").VerifiedAssetLoader;
62
+ workers: WasixWorkerGroup;
63
+ cache: Readonly<{
64
+ enabled: true;
65
+ namespace: string;
66
+ version: string;
67
+ storageReserveBytes: 0;
68
+ }>;
69
+ clangFilesystem: "snapshot" | "live";
70
+ sysrootProfile: "full" | "c-base-v1";
71
+ inspectSysroot: (profile?: string) => {
72
+ sha256: string;
73
+ entries: number;
74
+ files: number;
75
+ } | null;
76
+ prepareCommand: (invocation: HostCommandInvocation, signal: AbortSignal) => Promise<void>;
77
+ prepareClang(profile: "c" | "full", signal: AbortSignal): Promise<string[]>;
78
+ startShell(options?: Pick<WasixShellOptions, "mounts" | "args" | "cwd" | "env">, signal?: AbortSignal): Promise<WasixShellSession>;
79
+ dispose(): Promise<void>;
80
+ }>>;
@@ -0,0 +1,328 @@
1
+ import { createContainer, createContainerPackageManager, createVerifiedAssetLoader, validateDistribution, extractTarPackage } from '@wasm-idle/container';
2
+ import { createClangAdapter } from '@wasm-idle/container/adapters/clang';
3
+ import { createLiveClangAdapter } from '@wasm-idle/container/adapters/clang-live';
4
+ import { createLiveWasiAdapter } from '@wasm-idle/container/adapters/wasi-live';
5
+ import { clangSimdDriverArgs, installClangSimdHeaders } from '@wasm-idle/llvm-core/core/clang-simd';
6
+ import { createWasixShellSession, installWasixWorkerGroup } from '@wasm-idle/container/adapters/wasix';
7
+ export const BASH_BIN = '/usr/local/bin';
8
+ export const BASH_SYSROOT = '/usr/share/wasm-sysroot';
9
+ export const C_SYSROOT = '/usr/share/wasm-sysroot-c';
10
+ const TOOLCHAIN = '/opt/toolchains/llvm';
11
+ /** Expose the verified legacy sysroot through the canonical driver's automatic search paths. */
12
+ export function withCanonicalWasiPaths(entries) {
13
+ const additions = [];
14
+ for (const parent of ['include', 'lib']) {
15
+ if (entries.some((entry) => entry.path === `${parent}/wasm32-wasi` && entry.type === 'directory') &&
16
+ !entries.some((entry) => entry.path === `${parent}/wasm32-wasip1`))
17
+ additions.push({
18
+ path: `${parent}/wasm32-wasip1`,
19
+ type: 'symlink',
20
+ mode: 0o777,
21
+ target: 'wasm32-wasi'
22
+ });
23
+ }
24
+ const directory = 'lib/clang/22/lib/wasm32-unknown-wasip1';
25
+ const path = `${directory}/libclang_rt.builtins.a`;
26
+ if (!entries.some((entry) => entry.path === path) &&
27
+ entries.some((entry) => entry.path === 'lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a' &&
28
+ entry.type === 'file')) {
29
+ if (!entries.some((entry) => entry.path === directory))
30
+ additions.push({ path: directory, type: 'directory', mode: 0o755 });
31
+ additions.push({
32
+ path,
33
+ type: 'symlink',
34
+ mode: 0o777,
35
+ target: '../wasi/libclang_rt.builtins-wasm32.a'
36
+ });
37
+ }
38
+ return additions.length ? [...entries, ...additions] : entries;
39
+ }
40
+ const digest = async (bytes) => Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256', Uint8Array.from(bytes))), (value) => value.toString(16).padStart(2, '0')).join('');
41
+ /** Compose verified USTAR layers without changing retained header or file bytes. */
42
+ export function composeSysrootLayers(base, cxx) {
43
+ for (const layer of [base, cxx]) {
44
+ if (!(layer instanceof Uint8Array) ||
45
+ layer.length < 1024 ||
46
+ layer.length % 512 ||
47
+ layer.subarray(-1024).some((byte) => byte !== 0))
48
+ throw new Error('Invalid sysroot layer terminator');
49
+ }
50
+ const length = base.length + cxx.length - 1024;
51
+ if (length > 128 * 1024 * 1024)
52
+ throw new Error('Composed sysroot exceeds its archive budget');
53
+ const archive = new Uint8Array(length);
54
+ archive.set(base.subarray(0, -1024));
55
+ archive.set(cxx.subarray(0, -1024), base.length - 1024);
56
+ return archive;
57
+ }
58
+ /** A shared Bash/Clang owner. Importing this module does not load any runtime assets. */
59
+ export async function createBashProfile({ config, sdk, workspace, fetch: fetcher, onRecord, onInvocation, adapters = [], commands = {}, workerGroup, shellCommands = [], shellRoutes = {} }) {
60
+ const filesystem = config.clangFilesystem === undefined ? 'snapshot' : config.clangFilesystem;
61
+ if (filesystem !== 'snapshot' && filesystem !== 'live')
62
+ throw new TypeError('clangFilesystem must be snapshot or live');
63
+ const adapterId = filesystem === 'live' ? 'llvm-clang-tool-host-live-v1' : 'llvm-clang-tool-host-v1';
64
+ const layers = config.sysrootLayers;
65
+ if ((config.sysrootProfile !== undefined &&
66
+ !['full', 'c-base-v1'].includes(config.sysrootProfile)) ||
67
+ Boolean(layers) !== (config.sysrootProfile === 'c-base-v1'))
68
+ throw new Error('Explicit C base profile and pinned layers must be configured together');
69
+ if (layers &&
70
+ (layers.schemaVersion !== 1 ||
71
+ layers.basePackage !== 'llvm-sysroot-c' ||
72
+ layers.cxxPackage !== 'llvm-sysroot-cxx' ||
73
+ !/^[a-f0-9]{64}$/.test(layers.full?.sha256) ||
74
+ !Number.isSafeInteger(layers.full?.bytes) ||
75
+ layers.full.bytes < 1024 ||
76
+ layers.full.bytes > 128 * 1024 * 1024))
77
+ throw new Error('Invalid pinned sysroot layer configuration');
78
+ const distribution = await validateDistribution({
79
+ bytes: new TextEncoder().encode(config.manifest),
80
+ expectedSha256: config.manifestSha256,
81
+ adapterIds: ['wasi-preview1-live', adapterId],
82
+ allowedAssetURLs: config.assetURLs
83
+ });
84
+ const cache = Object.freeze({
85
+ enabled: true,
86
+ namespace: config.cacheNamespace,
87
+ version: config.manifestSha256,
88
+ storageReserveBytes: 0
89
+ });
90
+ const assetOptions = {
91
+ distribution,
92
+ fetch: fetcher,
93
+ persistentCache: cache,
94
+ maxCachedBytes: 192 * 1024 * 1024
95
+ };
96
+ const manager = createContainerPackageManager({
97
+ ...assetOptions,
98
+ capabilities: ['wasi-preview1', 'llvm-tool-host-exec-v1']
99
+ });
100
+ const shellAssets = createVerifiedAssetLoader({
101
+ ...assetOptions,
102
+ maxCachedBytes: 64 * 1024 * 1024
103
+ });
104
+ let workers;
105
+ let container;
106
+ let compiler;
107
+ try {
108
+ workers = workerGroup ?? installWasixWorkerGroup({ maxWorkers: config.maxWorkers ?? 32 });
109
+ compiler = (filesystem === 'live' ? createLiveClangAdapter : createClangAdapter)({
110
+ clangSha256: config.clangSha256,
111
+ linkerSha256: config.linkerSha256,
112
+ linkerPath: `${TOOLCHAIN}/bin/wasm-ld`,
113
+ compilerPaths: [`${TOOLCHAIN}/bin/llvm`],
114
+ ...(filesystem === 'live'
115
+ ? { moduleServices: config.clangModuleServices === true }
116
+ : {}),
117
+ executableOutputProfile: 'wasi-preview1-process',
118
+ workerFactory: () => new Worker(config.clangWorkerUrl, { type: 'module' })
119
+ });
120
+ container = createContainer({
121
+ workspace,
122
+ packages: manager,
123
+ commands,
124
+ maxBytes: workspace?.fs.maxBytes ?? 256 * 1024 * 1024,
125
+ adapters: [
126
+ ...adapters,
127
+ createLiveWasiAdapter({
128
+ maxBlockedIoMs: 120000,
129
+ workerFactory: () => new Worker(config.liveWorkerUrl, { type: 'module' })
130
+ }),
131
+ compiler
132
+ ],
133
+ artifactAdapter: 'wasi-preview1-live',
134
+ maxMemoryBytes: 2 ** 32,
135
+ maxProcesses: 8
136
+ });
137
+ }
138
+ catch (error) {
139
+ compiler?.clearModuleCache?.();
140
+ await workers?.dispose();
141
+ await manager.dispose();
142
+ await shellAssets.dispose();
143
+ throw error;
144
+ }
145
+ const routes = {
146
+ ...Object.fromEntries(shellCommands.map((name) => [`${BASH_BIN}/${name}`, { command: name }])),
147
+ [`${BASH_BIN}/clang`]: {
148
+ command: 'clang',
149
+ // Prepared release manifests may predate the current SIMD defaults.
150
+ args: clangSimdDriverArgs(BASH_SYSROOT),
151
+ stdio: filesystem === 'live' ? 'delegated' : 'forwarded'
152
+ },
153
+ [`${BASH_BIN}/wasm-run`]: { command: 'wasm-run' },
154
+ ...shellRoutes
155
+ };
156
+ const sysroots = new Map();
157
+ let session;
158
+ let starting;
159
+ let disposal;
160
+ const stop = new AbortController();
161
+ const prepareSysroot = async (requestedProfile, signal) => {
162
+ if (requestedProfile !== 'c' && requestedProfile !== 'full')
163
+ throw new Error('Unknown Clang sysroot profile');
164
+ const profile = !layers || requestedProfile === 'full' || sysroots.has('full') ? 'full' : 'c';
165
+ const root = profile === 'c' ? C_SYSROOT : BASH_SYSROOT;
166
+ const args = [
167
+ ...(profile === 'c'
168
+ ? [`--sysroot=${C_SYSROOT}`, `-resource-dir=${C_SYSROOT}/lib/clang/22`]
169
+ : []),
170
+ ...clangSimdDriverArgs(root)
171
+ ];
172
+ if (sysroots.has(profile))
173
+ return args;
174
+ // Each consumer owns its signal; the verified asset loader shares only fetches.
175
+ const prepared = await manager.prepare('llvm', { signal });
176
+ let archive;
177
+ if (layers) {
178
+ const base = await manager.prepare(layers.basePackage, { signal });
179
+ archive = base.packages
180
+ .find((pkg) => pkg.id === layers.basePackage)
181
+ ?.files.find((file) => file.path === 'sysroot.tar')?.bytes;
182
+ if (!archive)
183
+ throw new Error('Pinned LLVM profile has no base sysroot archive');
184
+ if (profile === 'full') {
185
+ const cxx = await manager.prepare(layers.cxxPackage, { signal });
186
+ const delta = cxx.packages
187
+ .find((pkg) => pkg.id === layers.cxxPackage)
188
+ ?.files.find((file) => file.path === 'sysroot.tar')?.bytes;
189
+ if (!delta)
190
+ throw new Error('Pinned LLVM profile has no C++ sysroot archive');
191
+ archive = composeSysrootLayers(archive, delta);
192
+ }
193
+ }
194
+ else
195
+ archive = prepared.packages
196
+ .find((pkg) => pkg.id === 'llvm')
197
+ ?.files.find((file) => file.path === 'sysroot.tar')?.bytes;
198
+ if (!archive)
199
+ throw new Error('Pinned LLVM profile has no sysroot archive');
200
+ const sha256 = await digest(archive);
201
+ signal.throwIfAborted();
202
+ if (layers &&
203
+ profile === 'full' &&
204
+ (archive.length !== layers.full.bytes || sha256 !== layers.full.sha256))
205
+ throw new Error('Composed sysroot does not match its pinned identity');
206
+ const entries = extractTarPackage(archive);
207
+ const metadata = {
208
+ sha256,
209
+ entries: entries.length,
210
+ files: entries.filter((file) => file.type === 'file').length
211
+ };
212
+ signal.throwIfAborted();
213
+ if (!sysroots.has(profile)) {
214
+ // The archive identity describes upstream bytes. Add the trusted application's
215
+ // SIMD headers only after verification, leaving its Clang resource headers intact.
216
+ const mounted = new Map(entries.map((entry) => [entry.path, entry]));
217
+ installClangSimdHeaders({
218
+ mkdirTree(path) {
219
+ let parent = '';
220
+ for (const part of path.slice(1).split('/')) {
221
+ parent = parent ? `${parent}/${part}` : part;
222
+ const existing = mounted.get(parent);
223
+ if (existing && existing.type !== 'directory')
224
+ throw new Error('SIMD header directory conflicts with the pinned sysroot');
225
+ if (!existing)
226
+ mounted.set(parent, { path: parent, type: 'directory', mode: 0o555 });
227
+ }
228
+ },
229
+ writeFile(path, data) {
230
+ const relative = path.slice(1);
231
+ if (mounted.has(relative))
232
+ throw new Error('SIMD header conflicts with the pinned sysroot');
233
+ mounted.set(relative, { path: relative, type: 'file', mode: 0o444, data });
234
+ }
235
+ });
236
+ container.fs.mountReadonly(root, withCanonicalWasiPaths([...mounted.values()]));
237
+ sysroots.set(profile, metadata);
238
+ }
239
+ return args;
240
+ };
241
+ const prepareCommand = async (invocation, signal) => {
242
+ onInvocation?.(invocation);
243
+ if (invocation.path === `${BASH_BIN}/clang`)
244
+ await prepareSysroot('full', signal);
245
+ };
246
+ return Object.freeze({
247
+ container,
248
+ manager,
249
+ shellAssets,
250
+ workers,
251
+ cache,
252
+ clangFilesystem: filesystem,
253
+ sysrootProfile: layers ? 'c-base-v1' : 'full',
254
+ inspectSysroot: (profile = 'full') => sysroots.get(profile) ?? null,
255
+ prepareCommand,
256
+ prepareClang(profile, signal) {
257
+ onInvocation?.({
258
+ path: `${BASH_BIN}/clang`,
259
+ argv: ['clang'],
260
+ env: [],
261
+ cwd: '/workspace',
262
+ stdin: null,
263
+ stdout: null,
264
+ stderr: null
265
+ });
266
+ return prepareSysroot(profile, signal);
267
+ },
268
+ startShell(options = {}, signal) {
269
+ if (starting || stop.signal.aborted)
270
+ return Promise.reject(new Error('The dedicated Bash owner has already started or retired'));
271
+ starting = createWasixShellSession({
272
+ container,
273
+ sdk,
274
+ workers,
275
+ assets: shellAssets,
276
+ sdkAsset: config.sdkAsset ?? { packageId: 'shell', assetId: 'sdk' },
277
+ shellAsset: config.shellAsset ?? { packageId: 'shell', assetId: 'bash' },
278
+ shellWasmSha256: config.bashWasmSha256,
279
+ sdkUrl: config.sdkUrl,
280
+ workerUrl: config.sdkWorkerUrl,
281
+ memory: config.memory,
282
+ routes,
283
+ mounts: options.mounts,
284
+ moduleDirectories: ['/workspace'],
285
+ timeoutMs: config.commandTimeoutMs,
286
+ args: options.args ?? ['--noprofile', '--norc'],
287
+ cwd: options.cwd ?? '/workspace',
288
+ env: {
289
+ PATH: `${BASH_BIN}:/usr/bin:/bin`,
290
+ HOME: '/workspace',
291
+ LANG: 'C',
292
+ ...options.env
293
+ },
294
+ signal: signal ? AbortSignal.any([signal, stop.signal]) : stop.signal,
295
+ prepareCommand,
296
+ onRecord
297
+ }).then((value) => {
298
+ session = value;
299
+ return value;
300
+ });
301
+ return starting;
302
+ },
303
+ dispose() {
304
+ return (disposal ??= (async () => {
305
+ stop.abort();
306
+ const errors = [];
307
+ for (const cleanup of [
308
+ () => workers.dispose(),
309
+ () => session?.dispose(),
310
+ () => container.dispose(),
311
+ () => compiler?.clearModuleCache?.(),
312
+ () => manager.dispose(),
313
+ () => shellAssets.dispose()
314
+ ]) {
315
+ try {
316
+ await cleanup();
317
+ }
318
+ catch (error) {
319
+ errors.push(error);
320
+ }
321
+ }
322
+ await starting?.catch(() => { });
323
+ if (errors.length)
324
+ throw new AggregateError(errors, 'Bash profile cleanup failed');
325
+ })());
326
+ }
327
+ });
328
+ }
@@ -0,0 +1,39 @@
1
+ import type { PlaygroundBinding, SandboxRuntimeAssets } from '../playground/sandbox.js';
2
+ import type { WorkspaceFile as ContainerWorkspaceFile } from '@wasm-idle/core';
3
+ import { type ContainerWorkerClient, type ContainerOwnerWorker } from './client.js';
4
+ import type { ContainerWorkerEvent, ContainerWorkspaceEntry } from './protocol.js';
5
+ export type ContainerPlaygroundBindingOptions = {
6
+ applicationRootURL: string;
7
+ workspaceId: string;
8
+ getLanguage?: () => string;
9
+ /** The app bundles this worker entry; no worker is created until first use. */
10
+ workerFactory?: () => ContainerOwnerWorker;
11
+ /** Deterministic transport contract tests only. */
12
+ clientFactory?: () => ContainerWorkerClient;
13
+ };
14
+ /** Structurally compatible with terminal UIs without depending on their components. */
15
+ export interface ContainerShellBinding {
16
+ connect(onOutput: (text: string) => void, onError?: (error: unknown) => void): Promise<void>;
17
+ write(text: string): Promise<void>;
18
+ eof(): Promise<void>;
19
+ interrupt(): Promise<void>;
20
+ dispose(): Promise<void>;
21
+ }
22
+ export interface ContainerPlaygroundBinding extends PlaygroundBinding {
23
+ readonly shell: ContainerShellBinding;
24
+ dispose(): Promise<void>;
25
+ inspect(): Promise<unknown>;
26
+ setShellDirectory(language: string): Promise<void>;
27
+ /** Claim the shared display at Bash's real primary prompt without consuming its input. */
28
+ beginTerminalExecution(): Promise<void>;
29
+ /** Redraw the actual Bash prompt after the Terminal has written its execution footer. */
30
+ endTerminalExecution(): Promise<void>;
31
+ syncWorkspace(language: string, files: readonly ContainerWorkspaceFile[]): Promise<void>;
32
+ readWorkspace(language: string): Promise<ContainerWorkspaceFile[]>;
33
+ listWorkspaceFiles(): Promise<ContainerWorkspaceEntry[]>;
34
+ publishedWorkspace(language: string): ContainerWorkspaceFile[];
35
+ acceptWorkspace(language: string, files: readonly ContainerWorkspaceFile[]): void;
36
+ onWorkspaceChange(listener: (event: ContainerWorkerEvent) => void): () => void;
37
+ }
38
+ /** Existing Terminal/Debug controls use this facade; every execution belongs to the owner Container. */
39
+ export declare function createContainerPlaygroundBinding(runtimeAssets: SandboxRuntimeAssets, options: ContainerPlaygroundBindingOptions): ContainerPlaygroundBinding;