@gadgetinc/substrate 0.1.0-rc.1

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 (181) hide show
  1. package/dist/assets/kernel.wasm +0 -0
  2. package/dist/assets/manifest.json +32 -0
  3. package/dist/assets/network-driver.js +2 -0
  4. package/dist/assets/network-driver.js.map +1 -0
  5. package/dist/assets/runtime.js +264 -0
  6. package/dist/assets/runtime.js.map +1 -0
  7. package/dist/binaries.d.ts +58 -0
  8. package/dist/binaries.d.ts.map +1 -0
  9. package/dist/boot/index.d.ts +318 -0
  10. package/dist/boot/index.d.ts.map +1 -0
  11. package/dist/index.d.ts +8 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +4589 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/kernel/bridge.d.ts +64 -0
  16. package/dist/kernel/bridge.d.ts.map +1 -0
  17. package/dist/kernel/types.d.ts +518 -0
  18. package/dist/kernel/types.d.ts.map +1 -0
  19. package/dist/kernel/wasm.d.ts +20 -0
  20. package/dist/kernel/wasm.d.ts.map +1 -0
  21. package/dist/node/assert.d.ts +99 -0
  22. package/dist/node/assert.d.ts.map +1 -0
  23. package/dist/node/async_hooks.d.ts +88 -0
  24. package/dist/node/async_hooks.d.ts.map +1 -0
  25. package/dist/node/buffer.d.ts +62 -0
  26. package/dist/node/buffer.d.ts.map +1 -0
  27. package/dist/node/child_process.d.ts +300 -0
  28. package/dist/node/child_process.d.ts.map +1 -0
  29. package/dist/node/cluster.d.ts +37 -0
  30. package/dist/node/cluster.d.ts.map +1 -0
  31. package/dist/node/constants.d.ts +306 -0
  32. package/dist/node/constants.d.ts.map +1 -0
  33. package/dist/node/crypto.d.ts +176 -0
  34. package/dist/node/crypto.d.ts.map +1 -0
  35. package/dist/node/dgram.d.ts +44 -0
  36. package/dist/node/dgram.d.ts.map +1 -0
  37. package/dist/node/diagnostics_channel.d.ts +57 -0
  38. package/dist/node/diagnostics_channel.d.ts.map +1 -0
  39. package/dist/node/dns.d.ts +278 -0
  40. package/dist/node/dns.d.ts.map +1 -0
  41. package/dist/node/domain.d.ts +21 -0
  42. package/dist/node/domain.d.ts.map +1 -0
  43. package/dist/node/events.d.ts +54 -0
  44. package/dist/node/events.d.ts.map +1 -0
  45. package/dist/node/fs/promises.d.ts +116 -0
  46. package/dist/node/fs/promises.d.ts.map +1 -0
  47. package/dist/node/fs.d.ts +536 -0
  48. package/dist/node/fs.d.ts.map +1 -0
  49. package/dist/node/http.d.ts +471 -0
  50. package/dist/node/http.d.ts.map +1 -0
  51. package/dist/node/http2.d.ts +508 -0
  52. package/dist/node/http2.d.ts.map +1 -0
  53. package/dist/node/https.d.ts +42 -0
  54. package/dist/node/https.d.ts.map +1 -0
  55. package/dist/node/inspector.d.ts +25 -0
  56. package/dist/node/inspector.d.ts.map +1 -0
  57. package/dist/node/net.d.ts +231 -0
  58. package/dist/node/net.d.ts.map +1 -0
  59. package/dist/node/os.d.ts +318 -0
  60. package/dist/node/os.d.ts.map +1 -0
  61. package/dist/node/path.d.ts +144 -0
  62. package/dist/node/path.d.ts.map +1 -0
  63. package/dist/node/process.d.ts +105 -0
  64. package/dist/node/process.d.ts.map +1 -0
  65. package/dist/node/punycode.d.ts +34 -0
  66. package/dist/node/punycode.d.ts.map +1 -0
  67. package/dist/node/querystring.d.ts +49 -0
  68. package/dist/node/querystring.d.ts.map +1 -0
  69. package/dist/node/readline.d.ts +99 -0
  70. package/dist/node/readline.d.ts.map +1 -0
  71. package/dist/node/stream.d.ts +409 -0
  72. package/dist/node/stream.d.ts.map +1 -0
  73. package/dist/node/string_decoder.d.ts +46 -0
  74. package/dist/node/string_decoder.d.ts.map +1 -0
  75. package/dist/node/timers.d.ts +79 -0
  76. package/dist/node/timers.d.ts.map +1 -0
  77. package/dist/node/tls.d.ts +159 -0
  78. package/dist/node/tls.d.ts.map +1 -0
  79. package/dist/node/trace_events.d.ts +18 -0
  80. package/dist/node/trace_events.d.ts.map +1 -0
  81. package/dist/node/tty.d.ts +67 -0
  82. package/dist/node/tty.d.ts.map +1 -0
  83. package/dist/node/url.d.ts +85 -0
  84. package/dist/node/url.d.ts.map +1 -0
  85. package/dist/node/util.d.ts +252 -0
  86. package/dist/node/util.d.ts.map +1 -0
  87. package/dist/node/v8.d.ts +134 -0
  88. package/dist/node/v8.d.ts.map +1 -0
  89. package/dist/node/vm.d.ts +89 -0
  90. package/dist/node/vm.d.ts.map +1 -0
  91. package/dist/node/wasi.d.ts +25 -0
  92. package/dist/node/wasi.d.ts.map +1 -0
  93. package/dist/node/worker_threads.d.ts +206 -0
  94. package/dist/node/worker_threads.d.ts.map +1 -0
  95. package/dist/node/ws.d.ts +110 -0
  96. package/dist/node/ws.d.ts.map +1 -0
  97. package/dist/node/zlib.d.ts +328 -0
  98. package/dist/node/zlib.d.ts.map +1 -0
  99. package/dist/persistence/opfs-store.d.ts +93 -0
  100. package/dist/persistence/opfs-store.d.ts.map +1 -0
  101. package/dist/runtime/async-function-shim.d.ts +27 -0
  102. package/dist/runtime/async-function-shim.d.ts.map +1 -0
  103. package/dist/runtime/fs-interface.d.ts +60 -0
  104. package/dist/runtime/fs-interface.d.ts.map +1 -0
  105. package/dist/runtime/index.d.ts +113 -0
  106. package/dist/runtime/index.d.ts.map +1 -0
  107. package/dist/runtime/loader.d.ts +50 -0
  108. package/dist/runtime/loader.d.ts.map +1 -0
  109. package/dist/runtime/loaders/async-transform.d.ts +40 -0
  110. package/dist/runtime/loaders/async-transform.d.ts.map +1 -0
  111. package/dist/runtime/loaders/cjs.d.ts +37 -0
  112. package/dist/runtime/loaders/cjs.d.ts.map +1 -0
  113. package/dist/runtime/loaders/detect-module-type.d.ts +21 -0
  114. package/dist/runtime/loaders/detect-module-type.d.ts.map +1 -0
  115. package/dist/runtime/loaders/esm.d.ts +140 -0
  116. package/dist/runtime/loaders/esm.d.ts.map +1 -0
  117. package/dist/runtime/loaders/source-map-registry.d.ts +43 -0
  118. package/dist/runtime/loaders/source-map-registry.d.ts.map +1 -0
  119. package/dist/runtime/loaders/source-map.d.ts +50 -0
  120. package/dist/runtime/loaders/source-map.d.ts.map +1 -0
  121. package/dist/runtime/loaders/utils.d.ts +6 -0
  122. package/dist/runtime/loaders/utils.d.ts.map +1 -0
  123. package/dist/runtime/native-globals.d.ts +24 -0
  124. package/dist/runtime/native-globals.d.ts.map +1 -0
  125. package/dist/runtime/network-driver.d.ts +78 -0
  126. package/dist/runtime/network-driver.d.ts.map +1 -0
  127. package/dist/runtime/process-context.d.ts +96 -0
  128. package/dist/runtime/process-context.d.ts.map +1 -0
  129. package/dist/runtime/process-event-loop.d.ts +356 -0
  130. package/dist/runtime/process-event-loop.d.ts.map +1 -0
  131. package/dist/runtime/process-handler.d.ts +71 -0
  132. package/dist/runtime/process-handler.d.ts.map +1 -0
  133. package/dist/runtime/process-handlers/node.d.ts +22 -0
  134. package/dist/runtime/process-handlers/node.d.ts.map +1 -0
  135. package/dist/runtime/process-handlers/npm.d.ts +20 -0
  136. package/dist/runtime/process-handlers/npm.d.ts.map +1 -0
  137. package/dist/runtime/process-handlers/npx.d.ts +11 -0
  138. package/dist/runtime/process-handlers/npx.d.ts.map +1 -0
  139. package/dist/runtime/process-handlers/pnpm.d.ts +12 -0
  140. package/dist/runtime/process-handlers/pnpm.d.ts.map +1 -0
  141. package/dist/runtime/process-handlers/shell.d.ts +24 -0
  142. package/dist/runtime/process-handlers/shell.d.ts.map +1 -0
  143. package/dist/runtime/process-handlers/yarn.d.ts +12 -0
  144. package/dist/runtime/process-handlers/yarn.d.ts.map +1 -0
  145. package/dist/runtime/process-helpers.d.ts +17 -0
  146. package/dist/runtime/process-helpers.d.ts.map +1 -0
  147. package/dist/runtime/process-manager.d.ts +87 -0
  148. package/dist/runtime/process-manager.d.ts.map +1 -0
  149. package/dist/runtime/process-scheduler.d.ts +123 -0
  150. package/dist/runtime/process-scheduler.d.ts.map +1 -0
  151. package/dist/runtime/process-waker.d.ts +24 -0
  152. package/dist/runtime/process-waker.d.ts.map +1 -0
  153. package/dist/runtime/promise.d.ts +44 -0
  154. package/dist/runtime/promise.d.ts.map +1 -0
  155. package/dist/runtime/stack-trace.d.ts +52 -0
  156. package/dist/runtime/stack-trace.d.ts.map +1 -0
  157. package/dist/runtime/wasm-package-interceptor.d.ts +141 -0
  158. package/dist/runtime/wasm-package-interceptor.d.ts.map +1 -0
  159. package/dist/runtime/web-streams.d.ts +57 -0
  160. package/dist/runtime/web-streams.d.ts.map +1 -0
  161. package/dist/runtime/websocket.d.ts +102 -0
  162. package/dist/runtime/websocket.d.ts.map +1 -0
  163. package/dist/shim/websocket-shim-inline.d.ts +9 -0
  164. package/dist/shim/websocket-shim-inline.d.ts.map +1 -0
  165. package/dist/shim/websocket-shim.d.ts +15 -0
  166. package/dist/shim/websocket-shim.d.ts.map +1 -0
  167. package/dist/sw/index.d.ts +53 -0
  168. package/dist/sw/index.d.ts.map +1 -0
  169. package/dist/utils/debug.d.ts +75 -0
  170. package/dist/utils/debug.d.ts.map +1 -0
  171. package/dist/utils/path.d.ts +20 -0
  172. package/dist/utils/path.d.ts.map +1 -0
  173. package/dist/utils/tarball.d.ts +37 -0
  174. package/dist/utils/tarball.d.ts.map +1 -0
  175. package/dist/utils/websocket-protocol.d.ts +102 -0
  176. package/dist/utils/websocket-protocol.d.ts.map +1 -0
  177. package/dist/worker/host.d.ts +14 -0
  178. package/dist/worker/host.d.ts.map +1 -0
  179. package/dist/worker/types.d.ts +209 -0
  180. package/dist/worker/types.d.ts.map +1 -0
  181. package/package.json +53 -0
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Set the native binding resolver function.
3
+ * Called by wasm-package-interceptor after it's initialized.
4
+ */
5
+ export declare function setNativeBindingResolver(resolver: (specifier: string) => string | null): void;
6
+ /**
7
+ * Get all registered aliases
8
+ */
9
+ export declare function getAliases(): Map<string, string>;
10
+ /**
11
+ * Register a module alias
12
+ * When code imports `fromName`, it will actually get `toName`
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * // Make require('esbuild') return require('esbuild-wasm')
17
+ * registerAlias('esbuild', 'esbuild-wasm');
18
+ * ```
19
+ */
20
+ export declare function registerAlias(fromName: string, toName: string): void;
21
+ /**
22
+ * Remove a module alias
23
+ */
24
+ export declare function removeAlias(fromName: string): void;
25
+ /**
26
+ * Apply aliases to a module specifier
27
+ * Handles exact matches, subpath imports, and native binding redirects
28
+ */
29
+ export declare function applyAlias(id: string): string;
30
+ /**
31
+ * Register a builtin module
32
+ */
33
+ export declare function registerBuiltin(name: string, exports: unknown): void;
34
+ /**
35
+ * Check if a module name is a builtin
36
+ */
37
+ export declare function isBuiltin(name: string): boolean;
38
+ /**
39
+ * Get list of builtin module names
40
+ */
41
+ export declare function getBuiltinModules(): [string, any][];
42
+ export declare function getModulePaths(dir: string): string[];
43
+ export declare function isFileAt(path: string): boolean;
44
+ export declare function isDirectoryAt(path: string): boolean;
45
+ /**
46
+ * Detect if a file contains ESM syntax by checking for import/export statements
47
+ * This is a fallback when package.json doesn't specify "type": "module"
48
+ */
49
+ export declare function detectESMSyntax(content: string): boolean;
50
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/runtime/loader.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,IAAI,CAE7F;AAaD;;GAEG;AACH,wBAAgB,UAAU,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAEhD;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAGpE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAElD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CA2B7C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAEpE;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI/C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAEnD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAcpD;AAOD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAM9C;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMnD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAmBxD"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Custom async/await → generator transform
3
+ *
4
+ * Replaces SWC's ES2016 targeting by converting async functions to generator-based
5
+ * equivalents. This ensures guest code continuations route through ProcessEventLoop
6
+ * (via SubstratePromise) instead of the browser's native microtask queue.
7
+ *
8
+ * Inspired by async-to-gen (Lee Byron). Uses acorn for parsing and MagicString
9
+ * for surgical source edits on original positions.
10
+ *
11
+ * Algorithm:
12
+ * 1. Parse source with acorn → full ESTree AST
13
+ * 2. Walk AST depth-first with scope tracking
14
+ * 3. On leaving async functions: remove `async`, wrap body in generator + __async()
15
+ * 4. On AwaitExpression: replace `await` → `yield` (with precedence parens)
16
+ * 5. On for-await-of: rewrite to manual iterator protocol
17
+ * 6. Extract `super` references in async methods into arrow-function bindings
18
+ * 7. Append only the runtime helpers actually used
19
+ */
20
+ import type MagicString from "magic-string";
21
+ type HelperName = "__async" | "__asyncGen" | "__asyncIterator";
22
+ export interface TransformAsyncOptions {
23
+ sourceType?: "module" | "script";
24
+ }
25
+ export interface TransformAsyncResult {
26
+ usedHelpers: Set<HelperName>;
27
+ }
28
+ /**
29
+ * Transform async/await to generators in-place on a MagicString.
30
+ *
31
+ * Parses the original source with acorn, walks the AST, and applies edits
32
+ * to the provided MagicString using original source positions. This allows
33
+ * composing with other MagicString edits (e.g., import/export rewriting)
34
+ * on the same instance without source map composition.
35
+ *
36
+ * Top-level await is NOT transformed (left for the TLA handler).
37
+ */
38
+ export declare function transformAsync(source: string, s: MagicString, options?: TransformAsyncOptions): TransformAsyncResult;
39
+ export {};
40
+ //# sourceMappingURL=async-transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-transform.d.ts","sourceRoot":"","sources":["../../../src/runtime/loaders/async-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAM5C,KAAK,UAAU,GAAG,SAAS,GAAG,YAAY,GAAG,iBAAiB,CAAC;AA+E/D,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAClC;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;CAC9B;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,CAAC,EAAE,WAAW,EACd,OAAO,CAAC,EAAE,qBAAqB,GAC9B,oBAAoB,CA+QtB"}
@@ -0,0 +1,37 @@
1
+ import type { ProcessContext } from "../process-context.js";
2
+ export interface Module {
3
+ id: string;
4
+ parent: Module | null;
5
+ exports: unknown;
6
+ children: Module[];
7
+ filename: string | null;
8
+ loaded: boolean;
9
+ path: string;
10
+ paths: string[];
11
+ require: (id: string) => unknown;
12
+ load: (filename: string) => void;
13
+ }
14
+ export interface ModuleConstructor {
15
+ new (id?: string, parent?: Module | null): Module;
16
+ _builtinModules: Map<string, unknown>;
17
+ builtinModules: string[];
18
+ isBuiltin: (id: string) => boolean;
19
+ Module: ModuleConstructor;
20
+ createRequire: (filenameOrURL: string | URL) => (id: string) => unknown;
21
+ _resolveFilename: (id: string, parent: Module | null) => string | null;
22
+ _cache: Map<string, Module>;
23
+ wrap: (source: string) => string;
24
+ _mainModule: Module | undefined;
25
+ runMain: (filename: string) => unknown;
26
+ _getModulePaths: (dir: string) => string[];
27
+ _nodeModulePaths: (dir: string) => string[];
28
+ }
29
+ export declare function createRequire(Module: ModuleConstructor, processContext: ProcessContext, parent?: Module | null): (id: string) => unknown;
30
+ export interface TransformResult {
31
+ code: string;
32
+ /** Source map JSON string (maps transpiled code back to original source) */
33
+ map: string | undefined;
34
+ }
35
+ export declare function transformCJS(source: string, filename?: string): TransformResult;
36
+ export declare const createModuleConstructor: (processContext: ProcessContext) => ModuleConstructor;
37
+ //# sourceMappingURL=cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cjs.d.ts","sourceRoot":"","sources":["../../../src/runtime/loaders/cjs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAkB5D,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IACjC,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AASD,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC;IAClD,eAAe,EAAE,GAAG,CAAC,MAAM,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or CommonJS.
5
+ * Used by both NodeHandler and worker_threads.
6
+ */
7
+ /**
8
+ * Check if the nearest package.json has "type": "module"
9
+ */
10
+ export declare function isPackageTypeModule(filename: string): boolean;
11
+ /**
12
+ * Determine if a file should be loaded as ESM based on:
13
+ * 1. File extension: .mjs = ESM, .cjs = CJS
14
+ * 2. Nearest package.json "type" field for .js files
15
+ * 3. Content detection (looks for import/export statements)
16
+ *
17
+ * @param filename - Absolute path to the file
18
+ * @returns true if the file should be loaded as ESM
19
+ */
20
+ export declare function shouldUseESM(filename: string): boolean;
21
+ //# sourceMappingURL=detect-module-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-module-type.d.ts","sourceRoot":"","sources":["../../../src/runtime/loaders/detect-module-type.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAsC7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAuCtD"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * ESM (ECMAScript Modules) support for Substrate
3
+ *
4
+ * Implements ES module loading with VFS-backed resolution.
5
+ * Uses es-module-lexer for robust parsing and magic-string for safe transformation.
6
+ * Uses a custom async/await → generator transform to compile out native async/await,
7
+ * ensuring guest continuations route through ProcessEventLoop instead of the
8
+ * browser's native microtask queue.
9
+ */
10
+ import MagicString from "magic-string";
11
+ import type { ProcessContext } from "../process-context.js";
12
+ import type { ModuleConstructor } from "./cjs.js";
13
+ /**
14
+ * Check if transpiled code contains top-level await.
15
+ *
16
+ * After the async transform compiles function-level async/await to generators,
17
+ * any remaining `await` keyword in the transformed code must be top-level
18
+ * await (TLA), since function-level awaits have been converted to `yield`.
19
+ *
20
+ * We simply check for any `await` keyword outside of strings and comments.
21
+ * We don't need to track brace depth because control-flow blocks (if, for, etc.)
22
+ * don't create function scopes - only function definitions do, and the async
23
+ * transform already handles those by converting async functions to generators.
24
+ */
25
+ export declare function hasTopLevelAwait(code: string): boolean;
26
+ /**
27
+ * Replace top-level `await` keywords with `yield` in transpiled code.
28
+ *
29
+ * After the async transform, all function-level async/await is compiled
30
+ * to generators. Any remaining `await` must be top-level await (TLA).
31
+ * We replace them with `yield` so the code can run inside a generator-based
32
+ * async wrapper that uses SubstratePromise instead of native async/await.
33
+ *
34
+ * Uses the same string/comment-aware scanning as hasTopLevelAwait to avoid
35
+ * replacing `await` inside string literals or comments.
36
+ */
37
+ export declare function replaceTopLevelAwaitWithYield(code: string): string;
38
+ /**
39
+ * Build the Node.js globals prologue for ESM modules.
40
+ *
41
+ * @param importedNames - Names already imported by the module (excluded from prologue to avoid redeclaration)
42
+ */
43
+ export declare function buildESMPrologue(importedNames?: Set<string>): string;
44
+ /**
45
+ * Transform ESM code through async/await compilation and TLA handling.
46
+ *
47
+ * Takes the original source and a MagicString that has already had its
48
+ * ESM import/export syntax rewritten, and applies async/await → generator
49
+ * transform edits to the same MagicString. This avoids source map
50
+ * composition since both transforms use original source positions.
51
+ *
52
+ * 1. Compile out function-level async/await via custom transform
53
+ * 2. Top-level await detection (any remaining `await` after transform is TLA)
54
+ * 3. If TLA: replaces `await` → `yield` and wraps in generator-based executor
55
+ * 4. Adds Node.js globals prologue
56
+ *
57
+ * @param originalSource - The original ESM source (for acorn parsing)
58
+ * @param magicString - MagicString with import/export edits already applied
59
+ * @param options - Transform options
60
+ * @returns Executable code, source map, and TLA flag
61
+ */
62
+ export declare function transformESMCode(originalSource: string, magicString: MagicString, options?: {
63
+ filename?: string;
64
+ importedNames?: Set<string>;
65
+ }): {
66
+ code: string;
67
+ map?: string;
68
+ hasTLA: boolean;
69
+ };
70
+ export type { ModuleConstructor };
71
+ /**
72
+ * ESModule class - represents a loaded ES module
73
+ */
74
+ declare class ESModule {
75
+ /** Module URL (file:// URL) */
76
+ url: string;
77
+ /** Absolute file path */
78
+ filename: string;
79
+ /** Module namespace object */
80
+ namespace: Record<string, unknown>;
81
+ /** Whether the module has been evaluated */
82
+ evaluated: boolean;
83
+ /**
84
+ * Promise that resolves when the module's top-level await completes.
85
+ * Set when a module (or one of its dependencies) has TLA that couldn't
86
+ * be resolved synchronously by the sync trampoline. Downstream importers
87
+ * must wait for this promise before executing.
88
+ */
89
+ tlaPromise?: PromiseLike<void>;
90
+ /** The module's default export */
91
+ private _default;
92
+ /** Named exports */
93
+ private _exports;
94
+ constructor(url: string);
95
+ /**
96
+ * Define a named export
97
+ */
98
+ defineExport(name: string, getter: () => unknown): void;
99
+ /**
100
+ * Set the default export
101
+ */
102
+ setDefault(value: unknown): void;
103
+ /**
104
+ * Get all export names
105
+ */
106
+ getExportNames(): string[];
107
+ }
108
+ /**
109
+ * ESM Loader instance - bound to a ProcessContext
110
+ */
111
+ export interface ESMLoader {
112
+ importModule: (specifier: string, fromDir?: string) => ESModule;
113
+ dynamicImport: (specifier: string, fromDir?: string) => Promise<unknown>;
114
+ createDynamicImport: (moduleUrl: string) => (specifier: string) => Promise<unknown>;
115
+ clearCache: () => void;
116
+ }
117
+ /**
118
+ * Create an ESM loader bound to a ProcessContext.
119
+ *
120
+ * This mirrors the CJS loader pattern - the loader is created with a ProcessContext
121
+ * and CJS Module constructor, allowing ESM/CJS interop.
122
+ *
123
+ * @param processContext - The process context for cwd, env, etc.
124
+ * @param Module - The CJS Module constructor for interop
125
+ */
126
+ export declare function createESMLoader(processContext: ProcessContext, Module: ModuleConstructor): ESMLoader;
127
+ /**
128
+ * Initialize the default ESM loader.
129
+ * Must be called before using standalone functions like importModule().
130
+ */
131
+ export declare function initDefaultLoader(processContext: ProcessContext, Module: ModuleConstructor): void;
132
+ /**
133
+ * Reset the default ESM loader (for tests)
134
+ */
135
+ export declare function resetDefaultLoader(): void;
136
+ export declare function importModule(specifier: string, fromDir?: string): ESModule;
137
+ export declare function dynamicImport(specifier: string, fromDir?: string): Promise<unknown>;
138
+ export declare function createDynamicImport(moduleUrl: string): (specifier: string) => Promise<unknown>;
139
+ export declare function clearESMCache(): void;
140
+ //# sourceMappingURL=esm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esm.d.ts","sourceRoot":"","sources":["../../../src/runtime/loaders/esm.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,WAAW,MAAM,cAAc,CAAC;AAMvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAalD;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAiEtD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA0ElE;AAyBD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAQpE;AAoDD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC7B,GACA;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CA8CjD;AAMD,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAElC;;GAEG;AACH,cAAM,QAAQ;IACZ,+BAA+B;IAC/B,GAAG,EAAE,MAAM,CAAC;IAEZ,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IAEjB,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IAExC,4CAA4C;IAC5C,SAAS,UAAS;IAEl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C,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnF;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAE9F;AAED,wBAAgB,aAAa,IAAI,IAAI,CAEpC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Source Map Registry
3
+ *
4
+ * Stores decoded source maps keyed by substrate:// URL so the stack trace
5
+ * hook can remap generated positions back to original source locations.
6
+ *
7
+ * Loaders register maps during compilation; the prepareStackTrace hook
8
+ * queries them when Error.stack is read.
9
+ */
10
+ export interface OriginalPosition {
11
+ source: string;
12
+ line: number;
13
+ column: number;
14
+ }
15
+ /**
16
+ * Register a source map for a substrate:// URL.
17
+ * Called by CJS and ESM loaders after compilation.
18
+ *
19
+ * The source map is expected to be already offset for the function body
20
+ * (prologue, wrapper lines, etc.). An additional offset is applied to
21
+ * account for V8's `new Function()` wrapper (2 lines) so that V8 CallSite
22
+ * line numbers can be used directly for lookups.
23
+ *
24
+ * @param substrateUrl - The substrate:// URL this map belongs to
25
+ * @param mapJson - Source map JSON (already offset for the body)
26
+ * @param bodyOffsetCorrection - Additional lines to offset beyond what's
27
+ * already in the source map. CJS passes 1 here because the join("\n")
28
+ * between prologue and wrapper lines adds 1 more newline than countLines
29
+ * accounts for.
30
+ */
31
+ export declare function registerSourceMap(substrateUrl: string, mapJson: string, bodyOffsetCorrection?: number): void;
32
+ /**
33
+ * Look up the original source position for a generated position.
34
+ *
35
+ * Lines and columns are 1-based (matching V8 CallSite conventions).
36
+ * Returns null if no mapping is found.
37
+ */
38
+ export declare function lookupOriginalPosition(substrateUrl: string, line: number, column: number): OriginalPosition | null;
39
+ /**
40
+ * Clear all registered source maps. Used in tests.
41
+ */
42
+ export declare function clearSourceMapRegistry(): void;
43
+ //# sourceMappingURL=source-map-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-map-registry.d.ts","sourceRoot":"","sources":["../../../src/runtime/loaders/source-map-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAWD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,oBAAoB,GAAE,MAAU,GAC/B,IAAI,CAiBN;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,gBAAgB,GAAG,IAAI,CAwCzB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Source map utilities for Substrate module loaders
3
+ *
4
+ * Provides helpers for:
5
+ * - Encoding source maps as inline data URLs
6
+ * - Offsetting source map line numbers (to account for prologues/wrappers)
7
+ * - Generating //# sourceURL and //# sourceMappingURL annotations
8
+ */
9
+ /**
10
+ * Encode a source map JSON string as a base64 data URL for inline embedding.
11
+ *
12
+ * Uses the TextEncoder → binary string → btoa path to handle non-ASCII
13
+ * characters (e.g. unicode in sourcesContent). Plain btoa() only accepts
14
+ * Latin-1, so we encode to UTF-8 bytes first.
15
+ */
16
+ export declare function encodeSourceMapDataURL(mapJson: string): string;
17
+ /**
18
+ * Offset a source map's generated line numbers by prepending empty lines.
19
+ *
20
+ * When we wrap transpiled code in a prologue or function wrapper, the actual
21
+ * source starts N lines into the function body. The source map needs to account
22
+ * for these extra lines. We prepend N semicolons to the `mappings` string —
23
+ * each semicolon represents an empty generated line with no mappings.
24
+ *
25
+ * @param mapJson - The source map as a JSON string
26
+ * @param lineOffset - Number of lines to prepend (e.g. prologue line count)
27
+ * @returns The adjusted source map as a JSON string
28
+ */
29
+ export declare function offsetSourceMapLines(mapJson: string, lineOffset: number): string;
30
+ /**
31
+ * Append source map annotations to code for use with `new Function()`.
32
+ *
33
+ * Appends both:
34
+ * - `//# sourceURL=<url>` — gives the code a filename in DevTools
35
+ * - `//# sourceMappingURL=data:...` — embeds the source map inline
36
+ *
37
+ * If no source map is provided, only the sourceURL is appended.
38
+ *
39
+ * @param code - The transpiled code
40
+ * @param sourceURL - The URL to associate with this code (e.g. `substrate:///path/to/file.js`)
41
+ * @param mapJson - Optional source map JSON string
42
+ * @returns The annotated code
43
+ */
44
+ export declare function annotateCode(code: string, sourceURL: string, mapJson?: string): string;
45
+ /**
46
+ * Count the number of newlines in a string.
47
+ * Used to determine how many lines a prologue or wrapper adds.
48
+ */
49
+ export declare function countLines(str: string): number;
50
+ //# sourceMappingURL=source-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-map.d.ts","sourceRoot":"","sources":["../../../src/runtime/loaders/source-map.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQ9D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAOhF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAWtF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM9C"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Strip shebang from the beginning of source code.
3
+ * Shebangs like #!/usr/bin/env node are valid in Node.js files but not valid JavaScript.
4
+ */
5
+ export declare function stripShebang(source: string): string;
6
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/runtime/loaders/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CASnD"}
@@ -0,0 +1,24 @@
1
+ export declare const nativeSetTimeout: typeof setTimeout;
2
+ export declare const nativeClearTimeout: typeof clearTimeout;
3
+ export declare const nativeSetInterval: typeof setInterval;
4
+ export declare const nativeClearInterval: typeof clearInterval;
5
+ export declare const nativeQueueMicrotask: typeof queueMicrotask;
6
+ export declare const nativePromise: PromiseConstructor;
7
+ export declare const nativeFetch: typeof fetch;
8
+ export declare const NativeReadableStream: {
9
+ new (underlyingSource: UnderlyingByteSource, strategy?: {
10
+ highWaterMark?: number | undefined;
11
+ } | undefined): ReadableStream<Uint8Array<ArrayBuffer>>;
12
+ new <R = any>(underlyingSource: UnderlyingDefaultSource<R>, strategy?: QueuingStrategy<R> | undefined): ReadableStream<R>;
13
+ new <R = any>(underlyingSource?: UnderlyingSource<R> | undefined, strategy?: QueuingStrategy<R> | undefined): ReadableStream<R>;
14
+ prototype: ReadableStream<any>;
15
+ };
16
+ export declare const NativeWritableStream: {
17
+ new <W = any>(underlyingSink?: UnderlyingSink<W> | undefined, strategy?: QueuingStrategy<W> | undefined): WritableStream<W>;
18
+ prototype: WritableStream<any>;
19
+ };
20
+ export declare const NativeTransformStream: {
21
+ new <I = any, O = any>(transformer?: Transformer<I, O> | undefined, writableStrategy?: QueuingStrategy<I> | undefined, readableStrategy?: QueuingStrategy<O> | undefined): TransformStream<I, O>;
22
+ prototype: TransformStream<any, any>;
23
+ };
24
+ //# sourceMappingURL=native-globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-globals.d.ts","sourceRoot":"","sources":["../../src/runtime/native-globals.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,gBAAgB,mBAAyC,CAAC;AACvE,eAAO,MAAM,kBAAkB,qBAA2C,CAAC;AAC3E,eAAO,MAAM,iBAAiB,oBAA0C,CAAC;AACzE,eAAO,MAAM,mBAAmB,sBAA4C,CAAC;AAC7E,eAAO,MAAM,oBAAoB,uBAA8C,CAAC;AAChF,eAAO,MAAM,aAAa,oBAAqB,CAAC;AAChD,eAAO,MAAM,WAAW,cAAoC,CAAC;AAG7D,eAAO,MAAM,oBAAoB;;;;;;;CAA4B,CAAC;AAC9D,eAAO,MAAM,oBAAoB;;;CAA4B,CAAC;AAC9D,eAAO,MAAM,qBAAqB;;;CAA6B,CAAC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Network Driver
3
+ *
4
+ * Bridges between the browser (Service Worker/fetch) and the kernel's virtual networking.
5
+ * This driver delivers incoming HTTP requests to the kernel and retrieves outbound responses.
6
+ *
7
+ * Architecture:
8
+ * 1. Client code calls http.createServer().listen(port)
9
+ * 2. Kernel creates a virtual server on that port
10
+ * 3. NetworkDriver registers to intercept requests to that port
11
+ * 4. When a request comes in:
12
+ * - NetworkDriver creates a connection in the kernel via deliver message
13
+ * - Kernel emits NetAccept event
14
+ * - http module creates IncomingMessage/ServerResponse
15
+ * - User code handles request
16
+ * - Response data is written to kernel connection
17
+ * - NetworkDriver reads outbound data and responds
18
+ */
19
+ import type { KernelBridge } from "../kernel/types.js";
20
+ export interface PendingRequest {
21
+ connId: number;
22
+ resolve: (response: Response) => void;
23
+ reject: (error: Error) => void;
24
+ responseHeaders: Headers | null;
25
+ responseStatus: number;
26
+ responseBody: Uint8Array[];
27
+ headersSent: boolean;
28
+ }
29
+ export declare class NetworkDriver {
30
+ private kernel;
31
+ private nextConnId;
32
+ private pendingRequests;
33
+ private listeningPorts;
34
+ constructor(kernel: KernelBridge);
35
+ /**
36
+ * Register a port that the kernel is listening on
37
+ */
38
+ registerPort(port: number): void;
39
+ /**
40
+ * Unregister a port
41
+ */
42
+ unregisterPort(port: number): void;
43
+ /**
44
+ * Check if a port is being listened on
45
+ */
46
+ isListening(port: number): boolean;
47
+ /**
48
+ * Get all listening ports
49
+ */
50
+ getListeningPorts(): number[];
51
+ /**
52
+ * Handle an incoming HTTP request
53
+ * This is called by the Service Worker or fetch interceptor
54
+ */
55
+ handleRequest(serverId: number, request: Request, port: number): Promise<Response>;
56
+ private deliverRequest;
57
+ /**
58
+ * Finalize the response and resolve the promise
59
+ */
60
+ private finalizeResponse;
61
+ /**
62
+ * Handle connection closed event
63
+ */
64
+ handleConnectionClosed(connId: number): void;
65
+ }
66
+ /**
67
+ * Initialize the network driver
68
+ */
69
+ export declare function initNetworkDriver(kernel: KernelBridge): NetworkDriver;
70
+ /**
71
+ * Get the current network driver
72
+ */
73
+ export declare function getNetworkDriver(): NetworkDriver;
74
+ /**
75
+ * Reset the network driver (for testing)
76
+ */
77
+ export declare function resetNetworkDriver(): void;
78
+ //# sourceMappingURL=network-driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network-driver.d.ts","sourceRoot":"","sources":["../../src/runtime/network-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMvD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IACtC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC/B,eAAe,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,UAAU,EAAE,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC;CACtB;AAMD,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,eAAe,CAAqC;IAC5D,OAAO,CAAC,cAAc,CAAqB;IAE3C,YAAY,MAAM,EAAE,YAAY,EAE/B;IAED;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE/B;IAED;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjC;IAED;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjC;IAED;;OAEG;IACH,iBAAiB,IAAI,MAAM,EAAE,CAE5B;IAED;;;OAGG;IACG,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkBvF;YAKa,cAAc;IAsC5B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAwBxB;;OAEG;IACH,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE3C;CACF;AAQD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,aAAa,CAarE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Process Context
3
+ *
4
+ * Each process gets its own isolated context containing:
5
+ * - Event loop (nextTick queue, timer heap, immediate queue, etc.)
6
+ * - Process object (env, argv, cwd, etc.)
7
+ * - Module cache
8
+ *
9
+ * This provides true Node.js-like process isolation where child processes
10
+ * don't share state with their parents.
11
+ *
12
+ * ## Stdio Architecture
13
+ *
14
+ * Each process has kernel-managed stdio pipes:
15
+ * - fd 0: stdin (read end)
16
+ * - fd 1: stdout (write end)
17
+ * - fd 2: stderr (write end)
18
+ *
19
+ * When a process writes to stdout/stderr, data goes to the kernel pipe buffer.
20
+ * A pump loop (driven by the browser event loop) reads from these pipes and
21
+ * delivers data to the appropriate destination:
22
+ * - For PID 1: postMessage to main thread
23
+ * - For child processes: parent's ChildProcess.stdout/stderr streams
24
+ */
25
+ import type { KernelBridge } from "../kernel/types.js";
26
+ /**
27
+ * Process creation options
28
+ */
29
+ export interface ProcessCreateOptions {
30
+ /** Parent process ID (0 for root process) */
31
+ ppid: number;
32
+ /** Current working directory */
33
+ cwd: string;
34
+ /** Environment variables (copied, not shared) */
35
+ env: Record<string, string | undefined>;
36
+ /** Command to execute */
37
+ command: string;
38
+ /** Command-line arguments */
39
+ argv: string[];
40
+ /** Kernel bridge (shared across all processes) */
41
+ kernel: KernelBridge;
42
+ }
43
+ /**
44
+ * Per-process context
45
+ *
46
+ * Contains all state that is isolated to a single process.
47
+ * Each spawn/fork creates a new ProcessContext.
48
+ */
49
+ export declare class ProcessContext {
50
+ /** Kernel-assigned process ID */
51
+ readonly pid: number;
52
+ /** Current working directory */
53
+ cwd: string;
54
+ /** Command to execute */
55
+ command: string;
56
+ /** Environment variables */
57
+ env: Record<string, string | undefined>;
58
+ /** Command-line arguments */
59
+ argv: string[];
60
+ stdout: WritableStreamLike;
61
+ stderr: WritableStreamLike;
62
+ kernel: KernelBridge;
63
+ _exited: boolean;
64
+ constructor(pid: number, options: ProcessCreateOptions);
65
+ writeStdout(data: string | Uint8Array): void;
66
+ writeStderr(data: string | Uint8Array): void;
67
+ exit(code?: number): void;
68
+ }
69
+ interface WritableStreamLike {
70
+ write(chunk: string | Uint8Array, encoding?: string, callback?: () => void): boolean;
71
+ end(chunk?: string | Uint8Array, encoding?: string, callback?: () => void): void;
72
+ isTTY: boolean;
73
+ writable: boolean;
74
+ columns?: number;
75
+ rows?: number;
76
+ clearLine?: (dir: -1 | 0 | 1, callback?: () => void) => boolean;
77
+ clearScreenDown?: (callback?: () => void) => boolean;
78
+ cursorTo?: (x: number, y?: number | (() => void), callback?: () => void) => boolean;
79
+ moveCursor?: (dx: number, dy: number, callback?: () => void) => boolean;
80
+ getWindowSize?: () => [number, number];
81
+ hasColors?: (count?: number | object, env?: object) => boolean;
82
+ getColorDepth?: (env?: object) => number;
83
+ on?: (...args: unknown[]) => WritableStreamLike;
84
+ once?: (...args: unknown[]) => WritableStreamLike;
85
+ emit?: (...args: unknown[]) => boolean;
86
+ addListener?: (...args: unknown[]) => WritableStreamLike;
87
+ removeListener?: (...args: unknown[]) => WritableStreamLike;
88
+ removeAllListeners?: (...args: unknown[]) => WritableStreamLike;
89
+ prependListener?: (...args: unknown[]) => WritableStreamLike;
90
+ prependOnceListener?: (...args: unknown[]) => WritableStreamLike;
91
+ listeners?: (event: string) => ((...args: unknown[]) => void)[];
92
+ listenerCount?: (event: string) => number;
93
+ eventNames?: () => string[];
94
+ }
95
+ export {};
96
+ //# sourceMappingURL=process-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-context.d.ts","sourceRoot":"","sources":["../../src/runtime/process-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AASvD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,kDAAkD;IAClD,MAAM,EAAE,YAAY,CAAC;CACtB;AAED;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,iCAAiC;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAC;IAEZ,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;IAEhB,4BAA4B;IAC5B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAExC,6BAA6B;IAC7B,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf,MAAM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