@secure-exec/core 0.2.1-rc.1 → 0.3.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 (248) hide show
  1. package/README.md +5 -5
  2. package/dist/binary.d.ts +4 -0
  3. package/dist/binary.js +25 -0
  4. package/dist/bytes.d.ts +2 -0
  5. package/dist/bytes.js +6 -0
  6. package/dist/callbacks.d.ts +41 -0
  7. package/dist/callbacks.js +94 -0
  8. package/dist/cargo.d.ts +2 -0
  9. package/dist/cargo.js +142 -0
  10. package/dist/correlation.d.ts +10 -0
  11. package/dist/correlation.js +49 -0
  12. package/dist/descriptors.d.ts +34 -0
  13. package/dist/descriptors.js +37 -0
  14. package/dist/event-buffer.d.ts +90 -0
  15. package/dist/event-buffer.js +313 -0
  16. package/dist/ext.d.ts +7 -0
  17. package/dist/ext.js +13 -0
  18. package/dist/filesystem.d.ts +41 -0
  19. package/dist/filesystem.js +70 -0
  20. package/dist/frame-payload-codec.d.ts +8 -0
  21. package/dist/frame-payload-codec.js +14 -0
  22. package/dist/frame-rpc.d.ts +38 -0
  23. package/dist/frame-rpc.js +73 -0
  24. package/dist/frame-stream.d.ts +27 -0
  25. package/dist/frame-stream.js +99 -0
  26. package/dist/framing.d.ts +7 -0
  27. package/dist/framing.js +22 -0
  28. package/dist/generated/AcpLimitsConfig.d.ts +4 -0
  29. package/dist/generated/AcpLimitsConfig.js +2 -0
  30. package/dist/generated/CreateVmConfig.d.ts +19 -0
  31. package/dist/generated/FsPermissionRule.d.ts +6 -0
  32. package/dist/generated/FsPermissionRuleSet.d.ts +6 -0
  33. package/dist/generated/FsPermissionRuleSet.js +1 -0
  34. package/dist/generated/FsPermissionScope.d.ts +3 -0
  35. package/dist/generated/FsPermissionScope.js +1 -0
  36. package/dist/generated/HttpLimitsConfig.d.ts +3 -0
  37. package/dist/generated/HttpLimitsConfig.js +2 -0
  38. package/dist/generated/JsModuleResolution.d.ts +1 -0
  39. package/dist/generated/JsModuleResolution.js +2 -0
  40. package/dist/generated/JsRuntimeConfig.d.ts +26 -0
  41. package/dist/generated/JsRuntimeConfig.js +1 -0
  42. package/dist/generated/JsRuntimeLimitsConfig.d.ts +7 -0
  43. package/dist/generated/JsRuntimeLimitsConfig.js +2 -0
  44. package/dist/generated/JsRuntimePlatform.d.ts +1 -0
  45. package/dist/generated/JsRuntimePlatform.js +2 -0
  46. package/dist/generated/MountPluginDescriptor.d.ts +4 -0
  47. package/dist/generated/MountPluginDescriptor.js +2 -0
  48. package/dist/generated/NativeRootFilesystemConfig.d.ts +5 -0
  49. package/dist/generated/NativeRootFilesystemConfig.js +1 -0
  50. package/dist/generated/PatternPermissionRule.d.ts +6 -0
  51. package/dist/generated/PatternPermissionRule.js +1 -0
  52. package/dist/generated/PatternPermissionRuleSet.d.ts +6 -0
  53. package/dist/generated/PatternPermissionRuleSet.js +1 -0
  54. package/dist/generated/PatternPermissionScope.d.ts +3 -0
  55. package/dist/generated/PatternPermissionScope.js +1 -0
  56. package/dist/generated/PermissionMode.d.ts +1 -0
  57. package/dist/generated/PermissionMode.js +2 -0
  58. package/dist/generated/PermissionsPolicy.d.ts +10 -0
  59. package/dist/generated/PermissionsPolicy.js +1 -0
  60. package/dist/generated/PluginLimitsConfig.d.ts +4 -0
  61. package/dist/generated/PluginLimitsConfig.js +2 -0
  62. package/dist/generated/PythonLimitsConfig.d.ts +5 -0
  63. package/dist/generated/PythonLimitsConfig.js +2 -0
  64. package/dist/generated/ResourceLimitsConfig.d.ts +22 -0
  65. package/dist/generated/ResourceLimitsConfig.js +2 -0
  66. package/dist/generated/RootFilesystemConfig.d.ts +9 -0
  67. package/dist/generated/RootFilesystemConfig.js +1 -0
  68. package/dist/generated/RootFilesystemEntry.d.ts +13 -0
  69. package/dist/generated/RootFilesystemEntry.js +1 -0
  70. package/dist/generated/RootFilesystemEntryEncoding.d.ts +1 -0
  71. package/dist/generated/RootFilesystemEntryEncoding.js +2 -0
  72. package/dist/generated/RootFilesystemEntryKind.d.ts +1 -0
  73. package/dist/generated/RootFilesystemEntryKind.js +2 -0
  74. package/dist/generated/RootFilesystemLowerDescriptor.d.ts +7 -0
  75. package/dist/generated/RootFilesystemLowerDescriptor.js +1 -0
  76. package/dist/generated/RootFilesystemMode.d.ts +1 -0
  77. package/dist/generated/RootFilesystemMode.js +2 -0
  78. package/dist/generated/ToolLimitsConfig.d.ts +10 -0
  79. package/dist/generated/ToolLimitsConfig.js +2 -0
  80. package/dist/generated/VmDnsConfig.d.ts +6 -0
  81. package/dist/generated/VmDnsConfig.js +2 -0
  82. package/dist/generated/VmLimitsConfig.d.ts +18 -0
  83. package/dist/generated/VmLimitsConfig.js +1 -0
  84. package/dist/generated/VmListenPolicyConfig.d.ts +5 -0
  85. package/dist/generated/VmListenPolicyConfig.js +2 -0
  86. package/dist/generated/WasmLimitsConfig.d.ts +5 -0
  87. package/dist/generated/WasmLimitsConfig.js +2 -0
  88. package/dist/generated-protocol.d.ts +1037 -0
  89. package/dist/generated-protocol.js +2887 -0
  90. package/dist/index.d.ts +24 -62
  91. package/dist/index.js +24 -53
  92. package/dist/json.d.ts +2 -0
  93. package/dist/json.js +20 -0
  94. package/dist/kernel-proxy.d.ts +149 -0
  95. package/dist/kernel-proxy.js +1733 -0
  96. package/dist/native-client.d.ts +41 -0
  97. package/dist/native-client.js +124 -0
  98. package/dist/node-runtime.d.ts +443 -0
  99. package/dist/node-runtime.js +569 -0
  100. package/dist/numbers.d.ts +1 -0
  101. package/dist/numbers.js +8 -0
  102. package/dist/ownership.d.ts +18 -0
  103. package/dist/ownership.js +77 -0
  104. package/dist/permissions.d.ts +29 -0
  105. package/dist/permissions.js +68 -0
  106. package/dist/process.d.ts +35 -0
  107. package/dist/process.js +125 -0
  108. package/dist/protocol-client.d.ts +46 -0
  109. package/dist/protocol-client.js +180 -0
  110. package/dist/protocol-frames.d.ts +68 -0
  111. package/dist/protocol-frames.js +139 -0
  112. package/dist/protocol-maps.d.ts +28 -0
  113. package/dist/protocol-maps.js +217 -0
  114. package/dist/protocol-schema.d.ts +10 -0
  115. package/dist/protocol-schema.js +11 -0
  116. package/dist/request-payloads.d.ts +137 -0
  117. package/dist/request-payloads.js +210 -0
  118. package/dist/response-payloads.d.ts +107 -0
  119. package/dist/response-payloads.js +161 -0
  120. package/dist/sidecar-client.d.ts +242 -0
  121. package/dist/sidecar-client.js +797 -0
  122. package/dist/state.d.ts +40 -0
  123. package/dist/state.js +44 -0
  124. package/dist/test-runtime.d.ts +526 -0
  125. package/dist/test-runtime.js +2119 -0
  126. package/dist/vm-config.d.ts +31 -0
  127. package/dist/vm-config.js +1 -0
  128. package/fixtures/alpine-defaults.json +520 -0
  129. package/fixtures/base-filesystem.json +528 -0
  130. package/package.json +193 -115
  131. package/LICENSE +0 -191
  132. package/dist/bridge-setup.d.ts +0 -6
  133. package/dist/bridge-setup.js +0 -9
  134. package/dist/esm-compiler.d.ts +0 -18
  135. package/dist/esm-compiler.js +0 -72
  136. package/dist/fs-helpers.d.ts +0 -23
  137. package/dist/fs-helpers.js +0 -41
  138. package/dist/generated/isolate-runtime.d.ts +0 -19
  139. package/dist/generated/isolate-runtime.js +0 -21
  140. package/dist/generated/polyfills.d.ts +0 -82
  141. package/dist/generated/polyfills.js +0 -82
  142. package/dist/isolate-runtime/apply-custom-global-policy.js +0 -53
  143. package/dist/isolate-runtime/apply-timing-mitigation-freeze.js +0 -130
  144. package/dist/isolate-runtime/apply-timing-mitigation-off.js +0 -14
  145. package/dist/isolate-runtime/bridge-attach.js +0 -29
  146. package/dist/isolate-runtime/bridge-initial-globals.js +0 -385
  147. package/dist/isolate-runtime/eval-script-result.js +0 -8
  148. package/dist/isolate-runtime/global-exposure-helpers.js +0 -36
  149. package/dist/isolate-runtime/init-commonjs-module-globals.js +0 -28
  150. package/dist/isolate-runtime/override-process-cwd.js +0 -8
  151. package/dist/isolate-runtime/override-process-env.js +0 -8
  152. package/dist/isolate-runtime/require-setup.js +0 -4153
  153. package/dist/isolate-runtime/set-commonjs-file-globals.js +0 -36
  154. package/dist/isolate-runtime/set-stdin-data.js +0 -10
  155. package/dist/isolate-runtime/setup-dynamic-import.js +0 -123
  156. package/dist/isolate-runtime/setup-fs-facade.js +0 -87
  157. package/dist/kernel/command-registry.d.ts +0 -44
  158. package/dist/kernel/command-registry.js +0 -114
  159. package/dist/kernel/device-backend.d.ts +0 -14
  160. package/dist/kernel/device-backend.js +0 -251
  161. package/dist/kernel/device-layer.d.ts +0 -12
  162. package/dist/kernel/device-layer.js +0 -271
  163. package/dist/kernel/dns-cache.d.ts +0 -29
  164. package/dist/kernel/dns-cache.js +0 -52
  165. package/dist/kernel/fd-table.d.ts +0 -84
  166. package/dist/kernel/fd-table.js +0 -278
  167. package/dist/kernel/file-lock.d.ts +0 -34
  168. package/dist/kernel/file-lock.js +0 -122
  169. package/dist/kernel/host-adapter.d.ts +0 -50
  170. package/dist/kernel/host-adapter.js +0 -8
  171. package/dist/kernel/index.d.ts +0 -36
  172. package/dist/kernel/index.js +0 -34
  173. package/dist/kernel/kernel.d.ts +0 -9
  174. package/dist/kernel/kernel.js +0 -1415
  175. package/dist/kernel/mount-table.d.ts +0 -75
  176. package/dist/kernel/mount-table.js +0 -353
  177. package/dist/kernel/permissions.d.ts +0 -36
  178. package/dist/kernel/permissions.js +0 -150
  179. package/dist/kernel/pipe-manager.d.ts +0 -64
  180. package/dist/kernel/pipe-manager.js +0 -267
  181. package/dist/kernel/proc-backend.d.ts +0 -30
  182. package/dist/kernel/proc-backend.js +0 -428
  183. package/dist/kernel/proc-layer.d.ts +0 -11
  184. package/dist/kernel/proc-layer.js +0 -507
  185. package/dist/kernel/process-table.d.ts +0 -126
  186. package/dist/kernel/process-table.js +0 -651
  187. package/dist/kernel/pty.d.ts +0 -109
  188. package/dist/kernel/pty.js +0 -552
  189. package/dist/kernel/socket-table.d.ts +0 -312
  190. package/dist/kernel/socket-table.js +0 -1188
  191. package/dist/kernel/timer-table.d.ts +0 -54
  192. package/dist/kernel/timer-table.js +0 -108
  193. package/dist/kernel/types.d.ts +0 -541
  194. package/dist/kernel/types.js +0 -98
  195. package/dist/kernel/user.d.ts +0 -29
  196. package/dist/kernel/user.js +0 -35
  197. package/dist/kernel/vfs.d.ts +0 -82
  198. package/dist/kernel/vfs.js +0 -25
  199. package/dist/kernel/wait.d.ts +0 -45
  200. package/dist/kernel/wait.js +0 -112
  201. package/dist/kernel/wstatus.d.ts +0 -21
  202. package/dist/kernel/wstatus.js +0 -33
  203. package/dist/module-resolver.d.ts +0 -29
  204. package/dist/module-resolver.js +0 -314
  205. package/dist/package-bundler.d.ts +0 -41
  206. package/dist/package-bundler.js +0 -497
  207. package/dist/runtime-driver.d.ts +0 -66
  208. package/dist/shared/api-types.d.ts +0 -83
  209. package/dist/shared/bridge-contract.d.ts +0 -772
  210. package/dist/shared/bridge-contract.js +0 -169
  211. package/dist/shared/console-formatter.d.ts +0 -22
  212. package/dist/shared/console-formatter.js +0 -161
  213. package/dist/shared/constants.d.ts +0 -3
  214. package/dist/shared/constants.js +0 -3
  215. package/dist/shared/errors.d.ts +0 -16
  216. package/dist/shared/errors.js +0 -21
  217. package/dist/shared/esm-utils.d.ts +0 -28
  218. package/dist/shared/esm-utils.js +0 -97
  219. package/dist/shared/global-exposure.d.ts +0 -38
  220. package/dist/shared/global-exposure.js +0 -876
  221. package/dist/shared/in-memory-fs.d.ts +0 -16
  222. package/dist/shared/in-memory-fs.js +0 -115
  223. package/dist/shared/permissions.d.ts +0 -36
  224. package/dist/shared/permissions.js +0 -314
  225. package/dist/shared/require-setup.d.ts +0 -6
  226. package/dist/shared/require-setup.js +0 -9
  227. package/dist/test/block-store-conformance.d.ts +0 -34
  228. package/dist/test/block-store-conformance.js +0 -251
  229. package/dist/test/metadata-store-conformance.d.ts +0 -37
  230. package/dist/test/metadata-store-conformance.js +0 -646
  231. package/dist/test/vfs-conformance.d.ts +0 -65
  232. package/dist/test/vfs-conformance.js +0 -842
  233. package/dist/types.d.ts +0 -98
  234. package/dist/types.js +0 -6
  235. package/dist/vfs/chunked-vfs.d.ts +0 -66
  236. package/dist/vfs/chunked-vfs.js +0 -1290
  237. package/dist/vfs/host-block-store.d.ts +0 -19
  238. package/dist/vfs/host-block-store.js +0 -97
  239. package/dist/vfs/memory-block-store.d.ts +0 -16
  240. package/dist/vfs/memory-block-store.js +0 -45
  241. package/dist/vfs/memory-metadata.d.ts +0 -75
  242. package/dist/vfs/memory-metadata.js +0 -528
  243. package/dist/vfs/sqlite-metadata.d.ts +0 -91
  244. package/dist/vfs/sqlite-metadata.js +0 -582
  245. package/dist/vfs/types.d.ts +0 -210
  246. package/dist/vfs/types.js +0 -8
  247. /package/dist/{runtime-driver.js → generated/CreateVmConfig.js} +0 -0
  248. /package/dist/{shared/api-types.js → generated/FsPermissionRule.js} +0 -0
@@ -1,35 +0,0 @@
1
- /**
2
- * User/group identity manager.
3
- *
4
- * Provides configurable uid/gid and passwd-entry generation for the kernel.
5
- * OS-level concern — lives in the kernel so all runtimes share the same identity.
6
- */
7
- export class UserManager {
8
- uid;
9
- gid;
10
- euid;
11
- egid;
12
- username;
13
- homedir;
14
- shell;
15
- gecos;
16
- constructor(config) {
17
- this.uid = config?.uid ?? 1000;
18
- this.gid = config?.gid ?? 1000;
19
- this.euid = config?.euid ?? this.uid;
20
- this.egid = config?.egid ?? this.gid;
21
- this.username = config?.username ?? "user";
22
- this.homedir = config?.homedir ?? "/home/user";
23
- this.shell = config?.shell ?? "/bin/sh";
24
- this.gecos = config?.gecos ?? "";
25
- }
26
- /** Generate a passwd-format string for the given uid. */
27
- getpwuid(uid) {
28
- if (uid === this.uid) {
29
- return `${this.username}:x:${this.uid}:${this.gid}:${this.gecos}:${this.homedir}:${this.shell}`;
30
- }
31
- // Generic entry for unknown uids
32
- const name = `user${uid}`;
33
- return `${name}:x:${uid}:${uid}::/home/${name}:/bin/sh`;
34
- }
35
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * Virtual Filesystem interface.
3
- *
4
- * POSIX-complete interface that all filesystem backends must implement.
5
- * The primary implementation is ChunkedVFS, which composes an FsMetadataStore
6
- * (directory tree, inodes, chunk mapping) with an FsBlockStore (key-value blob
7
- * store) to provide tiered storage with optional write buffering and versioning.
8
- *
9
- * Error behavior (KernelError codes):
10
- * - ENOENT: path does not exist (readFile, stat, pread, pwrite, truncate, readlink, etc.)
11
- * - EISDIR: operation targets a directory when a file is expected (readFile, pread, pwrite)
12
- * - ENOTDIR: intermediate path component is not a directory
13
- * - EEXIST: target already exists (createDir without recursive, link to existing)
14
- * - ELOOP: symlink resolution exceeds 40 levels
15
- * - ENOTEMPTY: removeDir on non-empty directory
16
- * - EPERM: link to directory
17
- * - EXDEV: cross-mount copy (raised by MountTable, not VFS directly)
18
- *
19
- * Optional methods (fsync, copy, readDirStat) may be absent. The kernel and
20
- * MountTable use optional chaining and provide fallbacks where needed.
21
- *
22
- * Usage: create via `createChunkedVfs()` from `./vfs/chunked-vfs.ts`, or use
23
- * `createInMemoryFileSystem()` from the package root for the default in-memory VFS.
24
- */
25
- export interface VirtualDirEntry {
26
- name: string;
27
- isDirectory: boolean;
28
- isSymbolicLink?: boolean;
29
- ino?: number;
30
- }
31
- export interface VirtualDirStatEntry extends VirtualDirEntry {
32
- stat: VirtualStat;
33
- }
34
- export interface VirtualStat {
35
- mode: number;
36
- size: number;
37
- isDirectory: boolean;
38
- isSymbolicLink: boolean;
39
- atimeMs: number;
40
- mtimeMs: number;
41
- ctimeMs: number;
42
- birthtimeMs: number;
43
- ino: number;
44
- nlink: number;
45
- uid: number;
46
- gid: number;
47
- }
48
- export interface VirtualFileSystem {
49
- readFile(path: string): Promise<Uint8Array>;
50
- readTextFile(path: string): Promise<string>;
51
- readDir(path: string): Promise<string[]>;
52
- readDirWithTypes(path: string): Promise<VirtualDirEntry[]>;
53
- writeFile(path: string, content: string | Uint8Array): Promise<void>;
54
- createDir(path: string): Promise<void>;
55
- mkdir(path: string, options?: {
56
- recursive?: boolean;
57
- }): Promise<void>;
58
- exists(path: string): Promise<boolean>;
59
- stat(path: string): Promise<VirtualStat>;
60
- removeFile(path: string): Promise<void>;
61
- removeDir(path: string): Promise<void>;
62
- rename(oldPath: string, newPath: string): Promise<void>;
63
- realpath(path: string): Promise<string>;
64
- symlink(target: string, linkPath: string): Promise<void>;
65
- readlink(path: string): Promise<string>;
66
- lstat(path: string): Promise<VirtualStat>;
67
- link(oldPath: string, newPath: string): Promise<void>;
68
- chmod(path: string, mode: number): Promise<void>;
69
- chown(path: string, uid: number, gid: number): Promise<void>;
70
- utimes(path: string, atime: number, mtime: number): Promise<void>;
71
- truncate(path: string, length: number): Promise<void>;
72
- /** Read a range from a file without loading the entire file into memory. */
73
- pread(path: string, offset: number, length: number): Promise<Uint8Array>;
74
- /** Write data at a specific offset without replacing the entire file. */
75
- pwrite(path: string, offset: number, data: Uint8Array): Promise<void>;
76
- /** Flush buffered writes for the given path to durable storage. */
77
- fsync?(path: string): Promise<void>;
78
- /** Copy a file within the same filesystem. */
79
- copy?(srcPath: string, dstPath: string): Promise<void>;
80
- /** Combined readdir + stat. Avoids N+1 queries for directory listings. */
81
- readDirStat?(path: string): Promise<VirtualDirStatEntry[]>;
82
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Virtual Filesystem interface.
3
- *
4
- * POSIX-complete interface that all filesystem backends must implement.
5
- * The primary implementation is ChunkedVFS, which composes an FsMetadataStore
6
- * (directory tree, inodes, chunk mapping) with an FsBlockStore (key-value blob
7
- * store) to provide tiered storage with optional write buffering and versioning.
8
- *
9
- * Error behavior (KernelError codes):
10
- * - ENOENT: path does not exist (readFile, stat, pread, pwrite, truncate, readlink, etc.)
11
- * - EISDIR: operation targets a directory when a file is expected (readFile, pread, pwrite)
12
- * - ENOTDIR: intermediate path component is not a directory
13
- * - EEXIST: target already exists (createDir without recursive, link to existing)
14
- * - ELOOP: symlink resolution exceeds 40 levels
15
- * - ENOTEMPTY: removeDir on non-empty directory
16
- * - EPERM: link to directory
17
- * - EXDEV: cross-mount copy (raised by MountTable, not VFS directly)
18
- *
19
- * Optional methods (fsync, copy, readDirStat) may be absent. The kernel and
20
- * MountTable use optional chaining and provide fallbacks where needed.
21
- *
22
- * Usage: create via `createChunkedVfs()` from `./vfs/chunked-vfs.ts`, or use
23
- * `createInMemoryFileSystem()` from the package root for the default in-memory VFS.
24
- */
25
- export {};
@@ -1,45 +0,0 @@
1
- /**
2
- * Unified blocking I/O wait system.
3
- *
4
- * Provides WaitHandle and WaitQueue primitives for all kernel subsystems
5
- * (pipes, sockets, flock, poll) to share the same wait/wake mechanism.
6
- * Promise-based — no Atomics.
7
- */
8
- /**
9
- * A single wait/wake handle. Callers await wait(), producers call wake().
10
- * Each handle resolves exactly once (either by wake or timeout).
11
- */
12
- export declare class WaitHandle {
13
- private resolve;
14
- private timer;
15
- private settled;
16
- readonly promise: Promise<void>;
17
- /** True if the handle resolved via timeout rather than wake(). */
18
- timedOut: boolean;
19
- constructor(timeoutMs?: number);
20
- /** Suspend until woken or timed out. */
21
- wait(): Promise<void>;
22
- /** Wake this handle. No-op if already settled. */
23
- wake(): void;
24
- /** Whether this handle has already been resolved. */
25
- get isSettled(): boolean;
26
- }
27
- /**
28
- * A FIFO queue of WaitHandles. Subsystems enqueue waiters and producers
29
- * wake them one-at-a-time or all-at-once.
30
- */
31
- export declare class WaitQueue {
32
- private waiters;
33
- /** Create and enqueue a new WaitHandle. */
34
- enqueue(timeoutMs?: number): WaitHandle;
35
- /** Remove a waiter from the queue without waking it. */
36
- remove(handle: WaitHandle): void;
37
- /** Wake exactly one waiter (FIFO order). Returns true if a waiter was woken. */
38
- wakeOne(): boolean;
39
- /** Wake all enqueued waiters. Returns the number woken. */
40
- wakeAll(): number;
41
- /** Number of pending (unsettled) waiters. */
42
- get pending(): number;
43
- /** Remove all waiters without waking them. */
44
- clear(): void;
45
- }
@@ -1,112 +0,0 @@
1
- /**
2
- * Unified blocking I/O wait system.
3
- *
4
- * Provides WaitHandle and WaitQueue primitives for all kernel subsystems
5
- * (pipes, sockets, flock, poll) to share the same wait/wake mechanism.
6
- * Promise-based — no Atomics.
7
- */
8
- /**
9
- * A single wait/wake handle. Callers await wait(), producers call wake().
10
- * Each handle resolves exactly once (either by wake or timeout).
11
- */
12
- export class WaitHandle {
13
- resolve = null;
14
- timer = null;
15
- settled = false;
16
- promise;
17
- /** True if the handle resolved via timeout rather than wake(). */
18
- timedOut = false;
19
- constructor(timeoutMs) {
20
- this.promise = new Promise((resolve) => {
21
- this.resolve = resolve;
22
- });
23
- if (timeoutMs !== undefined && timeoutMs >= 0) {
24
- this.timer = setTimeout(() => {
25
- if (!this.settled) {
26
- this.timedOut = true;
27
- this.settled = true;
28
- this.resolve();
29
- this.resolve = null;
30
- }
31
- }, timeoutMs);
32
- }
33
- }
34
- /** Suspend until woken or timed out. */
35
- wait() {
36
- return this.promise;
37
- }
38
- /** Wake this handle. No-op if already settled. */
39
- wake() {
40
- if (this.settled)
41
- return;
42
- this.settled = true;
43
- if (this.timer !== null) {
44
- clearTimeout(this.timer);
45
- this.timer = null;
46
- }
47
- this.resolve();
48
- this.resolve = null;
49
- }
50
- /** Whether this handle has already been resolved. */
51
- get isSettled() {
52
- return this.settled;
53
- }
54
- }
55
- /**
56
- * A FIFO queue of WaitHandles. Subsystems enqueue waiters and producers
57
- * wake them one-at-a-time or all-at-once.
58
- */
59
- export class WaitQueue {
60
- waiters = [];
61
- /** Create and enqueue a new WaitHandle. */
62
- enqueue(timeoutMs) {
63
- const handle = new WaitHandle(timeoutMs);
64
- this.waiters.push(handle);
65
- return handle;
66
- }
67
- /** Remove a waiter from the queue without waking it. */
68
- remove(handle) {
69
- const index = this.waiters.indexOf(handle);
70
- if (index >= 0) {
71
- this.waiters.splice(index, 1);
72
- }
73
- }
74
- /** Wake exactly one waiter (FIFO order). Returns true if a waiter was woken. */
75
- wakeOne() {
76
- while (this.waiters.length > 0) {
77
- const handle = this.waiters.shift();
78
- if (!handle.isSettled) {
79
- handle.wake();
80
- return true;
81
- }
82
- // Skip already-settled handles (timed out)
83
- }
84
- return false;
85
- }
86
- /** Wake all enqueued waiters. Returns the number woken. */
87
- wakeAll() {
88
- let count = 0;
89
- for (const handle of this.waiters) {
90
- if (!handle.isSettled) {
91
- handle.wake();
92
- count++;
93
- }
94
- }
95
- this.waiters.length = 0;
96
- return count;
97
- }
98
- /** Number of pending (unsettled) waiters. */
99
- get pending() {
100
- // Compact settled handles while counting
101
- let count = 0;
102
- for (const handle of this.waiters) {
103
- if (!handle.isSettled)
104
- count++;
105
- }
106
- return count;
107
- }
108
- /** Remove all waiters without waking them. */
109
- clear() {
110
- this.waiters.length = 0;
111
- }
112
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * POSIX wstatus encoding/decoding.
3
- *
4
- * Encodes how a process terminated into a single integer matching
5
- * the layout expected by WIFEXITED / WEXITSTATUS / WIFSIGNALED / WTERMSIG.
6
- *
7
- * Normal exit: (exitCode & 0xFF) << 8 (bits 8-15 = exit code, bits 0-6 = 0)
8
- * Signal death: signalNumber & 0x7F (bits 0-6 = signal, bits 8-15 = 0)
9
- */
10
- /** Encode a normal exit into POSIX wstatus. */
11
- export declare function encodeExitStatus(exitCode: number): number;
12
- /** Encode a signal death into POSIX wstatus. */
13
- export declare function encodeSignalStatus(signal: number): number;
14
- /** True if process exited normally (not killed by a signal). */
15
- export declare function WIFEXITED(status: number): boolean;
16
- /** Extract exit code (only valid when WIFEXITED is true). */
17
- export declare function WEXITSTATUS(status: number): number;
18
- /** True if process was killed by a signal. */
19
- export declare function WIFSIGNALED(status: number): boolean;
20
- /** Extract signal number (only valid when WIFSIGNALED is true). */
21
- export declare function WTERMSIG(status: number): number;
@@ -1,33 +0,0 @@
1
- /**
2
- * POSIX wstatus encoding/decoding.
3
- *
4
- * Encodes how a process terminated into a single integer matching
5
- * the layout expected by WIFEXITED / WEXITSTATUS / WIFSIGNALED / WTERMSIG.
6
- *
7
- * Normal exit: (exitCode & 0xFF) << 8 (bits 8-15 = exit code, bits 0-6 = 0)
8
- * Signal death: signalNumber & 0x7F (bits 0-6 = signal, bits 8-15 = 0)
9
- */
10
- /** Encode a normal exit into POSIX wstatus. */
11
- export function encodeExitStatus(exitCode) {
12
- return (exitCode & 0xff) << 8;
13
- }
14
- /** Encode a signal death into POSIX wstatus. */
15
- export function encodeSignalStatus(signal) {
16
- return signal & 0x7f;
17
- }
18
- /** True if process exited normally (not killed by a signal). */
19
- export function WIFEXITED(status) {
20
- return (status & 0x7f) === 0;
21
- }
22
- /** Extract exit code (only valid when WIFEXITED is true). */
23
- export function WEXITSTATUS(status) {
24
- return (status >> 8) & 0xff;
25
- }
26
- /** True if process was killed by a signal. */
27
- export function WIFSIGNALED(status) {
28
- return (status & 0x7f) !== 0;
29
- }
30
- /** Extract signal number (only valid when WIFSIGNALED is true). */
31
- export function WTERMSIG(status) {
32
- return status & 0x7f;
33
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * @deprecated Canonical source moved to @secure-exec/nodejs (US-003).
3
- * This copy is retained for backward compatibility during phased migration.
4
- * Will be removed in US-005 when kernel merges into core.
5
- *
6
- * Module classification and resolution helpers.
7
- *
8
- * Node built-ins are split into three tiers:
9
- * - Bridge modules: fully polyfilled by the bridge (fs, process, http, etc.)
10
- * - Deferred core modules: known but not yet bridge-supported; surfaced via
11
- * deferred stubs in require paths and polyfills/wrappers in ESM paths
12
- * - Unsupported core modules: known but intentionally unimplemented
13
- *
14
- * Everything else falls through to node-stdlib-browser polyfills or node_modules.
15
- */
16
- /**
17
- * Known named exports for each built-in module. Used by the ESM wrapper
18
- * generator to create `export const X = _builtin.X;` re-exports so that
19
- * `import { readFile } from 'fs'` works inside the isolate.
20
- */
21
- export declare const BUILTIN_NAMED_EXPORTS: Record<string, string[]>;
22
- /**
23
- * Normalize a module specifier to its canonical form if it's a known built-in.
24
- * Returns null for non-builtin specifiers.
25
- * Preserves the `node:` prefix when present, strips it otherwise.
26
- */
27
- export declare function normalizeBuiltinSpecifier(request: string): string | null;
28
- /** Extract the directory portion of a path (lightweight dirname without node:path). */
29
- export declare function getPathDir(path: string): string;