@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,12 +0,0 @@
1
- /**
2
- * Device layer.
3
- *
4
- * Intercepts device node paths (/dev/*) before they reach the VFS backend.
5
- * Wraps a VirtualFileSystem and handles device-specific read/write semantics.
6
- */
7
- import type { VirtualFileSystem } from "./vfs.js";
8
- /**
9
- * Wrap a VFS with device node interception.
10
- * Device paths are handled directly; all other paths pass through.
11
- */
12
- export declare function createDeviceLayer(vfs: VirtualFileSystem): VirtualFileSystem;
@@ -1,271 +0,0 @@
1
- /**
2
- * Device layer.
3
- *
4
- * Intercepts device node paths (/dev/*) before they reach the VFS backend.
5
- * Wraps a VirtualFileSystem and handles device-specific read/write semantics.
6
- */
7
- import { KernelError } from "./types.js";
8
- const DEVICE_PATHS = new Set([
9
- "/dev/null",
10
- "/dev/zero",
11
- "/dev/stdin",
12
- "/dev/stdout",
13
- "/dev/stderr",
14
- "/dev/urandom",
15
- "/dev/random",
16
- "/dev/tty",
17
- "/dev/console",
18
- "/dev/full",
19
- "/dev/ptmx",
20
- ]);
21
- const DEVICE_INO = {
22
- "/dev/null": 0xffff_0001,
23
- "/dev/zero": 0xffff_0002,
24
- "/dev/stdin": 0xffff_0003,
25
- "/dev/stdout": 0xffff_0004,
26
- "/dev/stderr": 0xffff_0005,
27
- "/dev/urandom": 0xffff_0006,
28
- "/dev/random": 0xffff_0007,
29
- "/dev/tty": 0xffff_0008,
30
- "/dev/console": 0xffff_0009,
31
- "/dev/full": 0xffff_000a,
32
- "/dev/ptmx": 0xffff_000b,
33
- };
34
- /** Device pseudo-directories that contain dynamic entries. */
35
- const DEVICE_DIRS = new Set(["/dev/fd", "/dev/pts", "/dev/shm"]);
36
- function isDevicePath(path) {
37
- return DEVICE_PATHS.has(path) || path.startsWith("/dev/fd/") || path.startsWith("/dev/pts/");
38
- }
39
- function isDeviceDir(path) {
40
- return path === "/dev" || DEVICE_DIRS.has(path);
41
- }
42
- function deviceStat(path) {
43
- const now = Date.now();
44
- return {
45
- mode: 0o666,
46
- size: 0,
47
- isDirectory: false,
48
- isSymbolicLink: false,
49
- atimeMs: now,
50
- mtimeMs: now,
51
- ctimeMs: now,
52
- birthtimeMs: now,
53
- ino: DEVICE_INO[path] ?? 0xffff_0000,
54
- nlink: 1,
55
- uid: 0,
56
- gid: 0,
57
- };
58
- }
59
- const DEV_DIR_ENTRIES = [
60
- { name: "null", isDirectory: false },
61
- { name: "zero", isDirectory: false },
62
- { name: "stdin", isDirectory: false },
63
- { name: "stdout", isDirectory: false },
64
- { name: "stderr", isDirectory: false },
65
- { name: "urandom", isDirectory: false },
66
- { name: "random", isDirectory: false },
67
- { name: "tty", isDirectory: false },
68
- { name: "console", isDirectory: false },
69
- { name: "full", isDirectory: false },
70
- { name: "ptmx", isDirectory: false },
71
- { name: "fd", isDirectory: true },
72
- { name: "pts", isDirectory: true },
73
- { name: "shm", isDirectory: true },
74
- ];
75
- /**
76
- * Wrap a VFS with device node interception.
77
- * Device paths are handled directly; all other paths pass through.
78
- */
79
- export function createDeviceLayer(vfs) {
80
- const wrapped = {
81
- prepareOpenSync(path, flags) {
82
- if (isDevicePath(path) || isDeviceDir(path))
83
- return false;
84
- const syncVfs = vfs;
85
- return syncVfs.prepareOpenSync?.(path, flags) ?? false;
86
- },
87
- async readFile(path) {
88
- if (path === "/dev/null" || path === "/dev/full")
89
- return new Uint8Array(0);
90
- if (path === "/dev/zero")
91
- return new Uint8Array(4096);
92
- if (path === "/dev/urandom" || path === "/dev/random") {
93
- const buf = new Uint8Array(4096);
94
- if (typeof globalThis.crypto?.getRandomValues === "function") {
95
- globalThis.crypto.getRandomValues(buf);
96
- }
97
- else {
98
- for (let i = 0; i < buf.length; i++) {
99
- buf[i] = (Math.random() * 256) | 0;
100
- }
101
- }
102
- return buf;
103
- }
104
- if (path === "/dev/tty" || path === "/dev/console" || path === "/dev/ptmx")
105
- return new Uint8Array(0);
106
- return vfs.readFile(path);
107
- },
108
- async pread(path, offset, length) {
109
- if (path === "/dev/null" || path === "/dev/full")
110
- return new Uint8Array(0);
111
- if (path === "/dev/zero")
112
- return new Uint8Array(length);
113
- if (path === "/dev/urandom" || path === "/dev/random") {
114
- const buf = new Uint8Array(length);
115
- if (typeof globalThis.crypto?.getRandomValues === "function") {
116
- globalThis.crypto.getRandomValues(buf);
117
- }
118
- else {
119
- for (let i = 0; i < buf.length; i++) {
120
- buf[i] = (Math.random() * 256) | 0;
121
- }
122
- }
123
- return buf;
124
- }
125
- if (path === "/dev/tty" || path === "/dev/console" || path === "/dev/ptmx")
126
- return new Uint8Array(0);
127
- return vfs.pread(path, offset, length);
128
- },
129
- async readTextFile(path) {
130
- if (path === "/dev/null")
131
- return "";
132
- const bytes = await this.readFile(path);
133
- return new TextDecoder().decode(bytes);
134
- },
135
- async readDir(path) {
136
- if (path === "/dev") {
137
- return DEV_DIR_ENTRIES.map((e) => e.name);
138
- }
139
- // /dev/fd and /dev/pts are dynamic — return empty at VFS level
140
- if (DEVICE_DIRS.has(path))
141
- return [];
142
- return vfs.readDir(path);
143
- },
144
- async readDirWithTypes(path) {
145
- if (path === "/dev") {
146
- return DEV_DIR_ENTRIES;
147
- }
148
- if (DEVICE_DIRS.has(path))
149
- return [];
150
- return vfs.readDirWithTypes(path);
151
- },
152
- async writeFile(path, content) {
153
- // /dev/full always returns ENOSPC on write (POSIX behavior)
154
- if (path === "/dev/full")
155
- throw new KernelError("ENOSPC", "No space left on device");
156
- // Discard writes to sink devices
157
- if (path === "/dev/null" || path === "/dev/zero" || path === "/dev/urandom"
158
- || path === "/dev/random" || path === "/dev/tty" || path === "/dev/console"
159
- || path === "/dev/ptmx")
160
- return;
161
- return vfs.writeFile(path, content);
162
- },
163
- async pwrite(path, offset, data) {
164
- if (path === "/dev/full")
165
- throw new KernelError("ENOSPC", "No space left on device");
166
- if (path === "/dev/null" || path === "/dev/zero" || path === "/dev/urandom"
167
- || path === "/dev/random" || path === "/dev/tty" || path === "/dev/console"
168
- || path === "/dev/ptmx")
169
- return;
170
- return vfs.pwrite(path, offset, data);
171
- },
172
- async createDir(path) {
173
- if (isDeviceDir(path))
174
- return;
175
- return vfs.createDir(path);
176
- },
177
- async mkdir(path, options) {
178
- if (isDeviceDir(path))
179
- return;
180
- return vfs.mkdir(path, options);
181
- },
182
- async exists(path) {
183
- if (isDevicePath(path) || isDeviceDir(path))
184
- return true;
185
- return vfs.exists(path);
186
- },
187
- async stat(path) {
188
- if (isDevicePath(path))
189
- return deviceStat(path);
190
- if (isDeviceDir(path)) {
191
- const now = Date.now();
192
- return {
193
- mode: 0o755,
194
- size: 0,
195
- isDirectory: true,
196
- isSymbolicLink: false,
197
- atimeMs: now,
198
- mtimeMs: now,
199
- ctimeMs: now,
200
- birthtimeMs: now,
201
- ino: DEVICE_INO[path] ?? 0xffff_0000,
202
- nlink: 2,
203
- uid: 0,
204
- gid: 0,
205
- };
206
- }
207
- return vfs.stat(path);
208
- },
209
- async removeFile(path) {
210
- if (isDevicePath(path))
211
- throw new KernelError("EPERM", "cannot remove device");
212
- return vfs.removeFile(path);
213
- },
214
- async removeDir(path) {
215
- if (isDeviceDir(path))
216
- throw new KernelError("EPERM", `cannot remove ${path}`);
217
- return vfs.removeDir(path);
218
- },
219
- async rename(oldPath, newPath) {
220
- if (isDevicePath(oldPath) || isDevicePath(newPath)) {
221
- throw new KernelError("EPERM", "cannot rename device");
222
- }
223
- return vfs.rename(oldPath, newPath);
224
- },
225
- async realpath(path) {
226
- if (isDevicePath(path) || isDeviceDir(path))
227
- return path;
228
- return vfs.realpath(path);
229
- },
230
- // Passthrough for POSIX extensions
231
- async symlink(target, linkPath) {
232
- return vfs.symlink(target, linkPath);
233
- },
234
- async readlink(path) {
235
- return vfs.readlink(path);
236
- },
237
- async lstat(path) {
238
- if (isDevicePath(path))
239
- return deviceStat(path);
240
- if (isDeviceDir(path))
241
- return this.stat(path);
242
- return vfs.lstat(path);
243
- },
244
- async link(oldPath, newPath) {
245
- if (isDevicePath(oldPath))
246
- throw new KernelError("EPERM", "cannot link device");
247
- return vfs.link(oldPath, newPath);
248
- },
249
- async chmod(path, mode) {
250
- if (isDevicePath(path))
251
- return;
252
- return vfs.chmod(path, mode);
253
- },
254
- async chown(path, uid, gid) {
255
- if (isDevicePath(path))
256
- return;
257
- return vfs.chown(path, uid, gid);
258
- },
259
- async utimes(path, atime, mtime) {
260
- if (isDevicePath(path))
261
- return;
262
- return vfs.utimes(path, atime, mtime);
263
- },
264
- async truncate(path, length) {
265
- if (isDevicePath(path))
266
- return;
267
- return vfs.truncate(path, length);
268
- },
269
- };
270
- return wrapped;
271
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * Kernel DNS cache shared across runtimes.
3
- *
4
- * Runtimes call kernel DNS cache before falling through to the host
5
- * adapter. Entries expire after their TTL.
6
- */
7
- import type { DnsResult } from "./host-adapter.js";
8
- export interface DnsCacheOptions {
9
- /** Default TTL in milliseconds when none is specified. Default: 30000 (30s). */
10
- defaultTtlMs?: number;
11
- }
12
- export declare class DnsCache {
13
- private cache;
14
- private defaultTtlMs;
15
- constructor(options?: DnsCacheOptions);
16
- /**
17
- * Look up a cached DNS result. Returns null on miss or expired entry.
18
- */
19
- lookup(hostname: string, rrtype: string): DnsResult | null;
20
- /**
21
- * Store a DNS result with TTL.
22
- * @param ttlMs TTL in milliseconds. Uses defaultTtlMs if not provided.
23
- */
24
- store(hostname: string, rrtype: string, result: DnsResult, ttlMs?: number): void;
25
- /** Flush all cached entries. */
26
- flush(): void;
27
- /** Number of entries (including possibly expired). */
28
- get size(): number;
29
- }
@@ -1,52 +0,0 @@
1
- /**
2
- * Kernel DNS cache shared across runtimes.
3
- *
4
- * Runtimes call kernel DNS cache before falling through to the host
5
- * adapter. Entries expire after their TTL.
6
- */
7
- export class DnsCache {
8
- cache = new Map();
9
- defaultTtlMs;
10
- constructor(options) {
11
- this.defaultTtlMs = options?.defaultTtlMs ?? 30_000;
12
- }
13
- /**
14
- * Look up a cached DNS result. Returns null on miss or expired entry.
15
- */
16
- lookup(hostname, rrtype) {
17
- const key = cacheKey(hostname, rrtype);
18
- const entry = this.cache.get(key);
19
- if (!entry)
20
- return null;
21
- // Expired — remove and return miss
22
- if (Date.now() >= entry.expiresAt) {
23
- this.cache.delete(key);
24
- return null;
25
- }
26
- return entry.result;
27
- }
28
- /**
29
- * Store a DNS result with TTL.
30
- * @param ttlMs TTL in milliseconds. Uses defaultTtlMs if not provided.
31
- */
32
- store(hostname, rrtype, result, ttlMs) {
33
- const key = cacheKey(hostname, rrtype);
34
- const ttl = ttlMs ?? this.defaultTtlMs;
35
- this.cache.set(key, {
36
- result,
37
- expiresAt: Date.now() + ttl,
38
- });
39
- }
40
- /** Flush all cached entries. */
41
- flush() {
42
- this.cache.clear();
43
- }
44
- /** Number of entries (including possibly expired). */
45
- get size() {
46
- return this.cache.size;
47
- }
48
- }
49
- /** Canonical cache key: "hostname:rrtype" */
50
- function cacheKey(hostname, rrtype) {
51
- return `${hostname}:${rrtype}`;
52
- }
@@ -1,84 +0,0 @@
1
- /**
2
- * Per-PID file descriptor table.
3
- *
4
- * Each process gets its own FD number space. Multiple FDs can share the
5
- * same FileDescription (via dup/dup2), which shares the cursor position.
6
- * Standard FDs 0-2 are pre-allocated per process.
7
- */
8
- import type { FDEntry, FDStat, FileDescription } from "./types.js";
9
- /** Maximum open FDs per process before allocations are rejected (EMFILE). */
10
- export declare const MAX_FDS_PER_PROCESS = 256;
11
- /** Allocator function that creates a FileDescription with a unique ID. */
12
- export type DescriptionAllocator = (path: string, flags: number) => FileDescription;
13
- /**
14
- * FD table for a single process.
15
- *
16
- * Manages FD allocation, dup/dup2, and shared cursor via FileDescription.
17
- */
18
- export declare class ProcessFDTable {
19
- private entries;
20
- private nextFd;
21
- private allocDesc;
22
- constructor(allocDesc: DescriptionAllocator);
23
- /** Pre-allocate stdin, stdout, stderr */
24
- initStdio(stdinDesc: FileDescription, stdoutDesc: FileDescription, stderrDesc: FileDescription): void;
25
- /** Pre-allocate stdin, stdout, stderr with custom filetypes (for pipe wiring). */
26
- initStdioWithTypes(stdinDesc: FileDescription, stdinType: number, stdoutDesc: FileDescription, stdoutType: number, stderrDesc: FileDescription, stderrType: number): void;
27
- /** Open a new FD for the given path and flags */
28
- open(path: string, flags: number, filetype?: number): number;
29
- /** Open a new FD pointing to an existing FileDescription (for pipes, inherited FDs) */
30
- openWith(description: FileDescription, filetype: number, targetFd?: number): number;
31
- get(fd: number): FDEntry | undefined;
32
- /** Close an FD. Decrements the refcount on the shared FileDescription. */
33
- close(fd: number): boolean;
34
- /** Duplicate an FD — new FD shares the same FileDescription (cursor). cloexec cleared on new FD (POSIX). */
35
- dup(fd: number): number;
36
- /** Duplicate FD to lowest available >= minFd (F_DUPFD). cloexec cleared on new FD. */
37
- dupMinFd(fd: number, minFd: number): number;
38
- /** Duplicate oldFd to newFd. Closes newFd first if open. cloexec cleared on new FD (POSIX). */
39
- dup2(oldFd: number, newFd: number): void;
40
- stat(fd: number): FDStat;
41
- /** Create a copy of this table for a child process (FD inheritance). Skips cloexec FDs. */
42
- fork(): ProcessFDTable;
43
- /** Close all FDs, decrementing all refcounts. */
44
- closeAll(): void;
45
- /** Iterate all FD entries (for cleanup inspection). */
46
- [Symbol.iterator](): IterableIterator<FDEntry>;
47
- private allocateFd;
48
- }
49
- /**
50
- * Kernel-level FD table manager.
51
- * Owns per-PID FD tables and coordinates shared FileDescriptions.
52
- */
53
- export declare class FDTableManager {
54
- private tables;
55
- private nextDescriptionId;
56
- /** Per-instance allocator bound to this manager's ID counter. */
57
- private allocDesc;
58
- /** Create a new FD table for a process with standard FDs. */
59
- create(pid: number): ProcessFDTable;
60
- /**
61
- * Create a new FD table with custom stdio FileDescriptions.
62
- * Used for pipe wiring: pass a pipe read/write end as stdin/stdout/stderr.
63
- * Null entries fall back to default device nodes.
64
- */
65
- createWithStdio(pid: number, stdinOverride: {
66
- description: FileDescription;
67
- filetype: number;
68
- } | null, stdoutOverride: {
69
- description: FileDescription;
70
- filetype: number;
71
- } | null, stderrOverride: {
72
- description: FileDescription;
73
- filetype: number;
74
- } | null): ProcessFDTable;
75
- /** Create a child FD table by forking the parent's. */
76
- fork(parentPid: number, childPid: number): ProcessFDTable;
77
- get(pid: number): ProcessFDTable | undefined;
78
- /** Check whether a PID has an FD table. */
79
- has(pid: number): boolean;
80
- /** Number of active FD tables. */
81
- get size(): number;
82
- /** Remove and close all FDs for a process. */
83
- remove(pid: number): void;
84
- }