@deepseek-ai/dsh-experimental-webworker-runtime 0.1.6-alpha.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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +75 -0
  4. package/README.zh.md +75 -0
  5. package/lib/client.js +854 -0
  6. package/lib/index.js +3506 -0
  7. package/lib/types/client/apply-injections.d.ts +15 -0
  8. package/lib/types/client/client.d.ts +102 -0
  9. package/lib/types/client/index.d.ts +66 -0
  10. package/lib/types/client/source-chooser.d.ts +8 -0
  11. package/lib/types/compile/transform.d.ts +39 -0
  12. package/lib/types/fixture-manifest.d.ts +26 -0
  13. package/lib/types/image-layout.d.ts +43 -0
  14. package/lib/types/index.d.ts +23 -0
  15. package/lib/types/module-proxies.d.ts +25 -0
  16. package/lib/types/module-system/module-loader.d.ts +177 -0
  17. package/lib/types/module-system/posix-path.d.ts +98 -0
  18. package/lib/types/node/builtin_modules/implemented/abort-error.d.ts +11 -0
  19. package/lib/types/node/builtin_modules/implemented/async_hooks.d.ts +174 -0
  20. package/lib/types/node/builtin_modules/implemented/buffer.d.ts +28 -0
  21. package/lib/types/node/builtin_modules/implemented/child_process.d.ts +178 -0
  22. package/lib/types/node/builtin_modules/implemented/crypto.d.ts +53 -0
  23. package/lib/types/node/builtin_modules/implemented/events.d.ts +84 -0
  24. package/lib/types/node/builtin_modules/implemented/fs/promises.d.ts +39 -0
  25. package/lib/types/node/builtin_modules/implemented/fs-watch.d.ts +119 -0
  26. package/lib/types/node/builtin_modules/implemented/fs.d.ts +502 -0
  27. package/lib/types/node/builtin_modules/implemented/http.d.ts +113 -0
  28. package/lib/types/node/builtin_modules/implemented/module.d.ts +50 -0
  29. package/lib/types/node/builtin_modules/implemented/os.d.ts +115 -0
  30. package/lib/types/node/builtin_modules/implemented/path.d.ts +138 -0
  31. package/lib/types/node/builtin_modules/implemented/perf_hooks.d.ts +13 -0
  32. package/lib/types/node/builtin_modules/implemented/stream.d.ts +22 -0
  33. package/lib/types/node/builtin_modules/implemented/timers/promises.d.ts +36 -0
  34. package/lib/types/node/builtin_modules/implemented/tty.d.ts +18 -0
  35. package/lib/types/node/builtin_modules/implemented/url.d.ts +61 -0
  36. package/lib/types/node/builtin_modules/implemented/util/types.d.ts +12 -0
  37. package/lib/types/node/builtin_modules/implemented/util.d.ts +95 -0
  38. package/lib/types/node/builtin_modules/implemented/zlib.d.ts +65 -0
  39. package/lib/types/node/builtin_modules/mock/dns/promises.d.ts +10 -0
  40. package/lib/types/node/builtin_modules/mock/net.d.ts +61 -0
  41. package/lib/types/node/builtin_modules/mock/sqlite.d.ts +19 -0
  42. package/lib/types/node/builtin_modules/mock/vm.d.ts +25 -0
  43. package/lib/types/node/builtin_modules/mock/worker_threads.d.ts +34 -0
  44. package/lib/types/node/builtins.d.ts +13 -0
  45. package/lib/types/node/external_packages/koffi.d.ts +63 -0
  46. package/lib/types/node/external_packages/node-addon-system-flock.d.ts +19 -0
  47. package/lib/types/node/external_packages/node-pty.d.ts +13 -0
  48. package/lib/types/node/external_packages/pi-ai.d.ts +51 -0
  49. package/lib/types/node/external_packages/replaced-externals.d.ts +9 -0
  50. package/lib/types/node/external_packages/ripgrep.d.ts +16 -0
  51. package/lib/types/node/external_packages/sharp.d.ts +6 -0
  52. package/lib/types/node/external_packages/ws.d.ts +38 -0
  53. package/lib/types/node/globals/crypto.d.ts +3 -0
  54. package/lib/types/node/globals/process.d.ts +78 -0
  55. package/lib/types/node/globals/timers.d.ts +10 -0
  56. package/lib/types/node/notImplementedFail.d.ts +34 -0
  57. package/lib/types/node/process-table.d.ts +50 -0
  58. package/lib/types/polyfill/async-context/als-runtime.d.ts +45 -0
  59. package/lib/types/polyfill/async-context/async-context-hooks.d.ts +6 -0
  60. package/lib/types/shell/ast.d.ts +23 -0
  61. package/lib/types/shell/expand.d.ts +65 -0
  62. package/lib/types/shell/fs-access.d.ts +43 -0
  63. package/lib/types/shell/interpret.d.ts +54 -0
  64. package/lib/types/shell/process/child.d.ts +26 -0
  65. package/lib/types/shell/process/host.d.ts +58 -0
  66. package/lib/types/shell/process/landlock.d.ts +33 -0
  67. package/lib/types/shell/process/protocol.d.ts +74 -0
  68. package/lib/types/shell/process/virtual-executables.d.ts +49 -0
  69. package/lib/types/shell/programs/builtins.d.ts +9 -0
  70. package/lib/types/shell/programs/files.d.ts +11 -0
  71. package/lib/types/shell/programs/index.d.ts +14 -0
  72. package/lib/types/shell/programs/options.d.ts +40 -0
  73. package/lib/types/shell/programs/text.d.ts +9 -0
  74. package/lib/types/shell/types.d.ts +138 -0
  75. package/lib/types/storage/active.d.ts +18 -0
  76. package/lib/types/storage/image-gzip.d.ts +39 -0
  77. package/lib/types/storage/memory.d.ts +308 -0
  78. package/lib/types/storage/paths.d.ts +18 -0
  79. package/lib/types/storage/tar.d.ts +41 -0
  80. package/lib/types/storage/types.d.ts +279 -0
  81. package/lib/types/transport/frames.d.ts +108 -0
  82. package/lib/types/transport/synthetic-http.d.ts +50 -0
  83. package/lib/types/transport/tunnel.d.ts +132 -0
  84. package/lib/types/worker-host.d.ts +165 -0
  85. package/lib/types/worker.d.ts +2 -0
  86. package/lib/worker.js +21879 -0
  87. package/package.json +73 -0
@@ -0,0 +1,308 @@
1
+ import type { Vfs, VfsBigIntStats, VfsDir, VfsDirent, VfsFileHandle, VfsOpenFile, VfsMutationListener, VfsMutationSink, VfsReadOptions, VfsSeedOptions, VfsStatOptions, VfsStats, VfsWriteOptions } from './types.ts';
2
+ /** Construction inputs for {@link MemoryVfs}. */
3
+ export interface MemoryVfsOptions {
4
+ /** Durable write-behind observer; absent leaves the filesystem ephemeral. */
5
+ readonly sink?: VfsMutationSink;
6
+ }
7
+ /**
8
+ * Filesystem held in two maps: one for file bytes, one for directories.
9
+ * Every path is normalized to an absolute POSIX path without a trailing
10
+ * separator, so callers may pass either form.
11
+ */
12
+ export declare class MemoryVfs implements Vfs {
13
+ private readonly files;
14
+ private readonly directories;
15
+ /** Directory permission bits; absence means {@link DEFAULT_DIRECTORY_MODE}. */
16
+ private readonly directoryModes;
17
+ /** Directory mtimes advance when their immediate entry set changes. */
18
+ private readonly directoryMtimes;
19
+ private readonly mutationListeners;
20
+ private readonly sink;
21
+ private temporaries;
22
+ private readonly identities;
23
+ private lastIdentity;
24
+ /**
25
+ * Build the synchronous filesystem authority.
26
+ * @param options - Optional durable write-behind sink.
27
+ */
28
+ constructor(options?: MemoryVfsOptions);
29
+ /**
30
+ * Settle the durable sink without changing in-memory success.
31
+ * @returns A promise that resolves when all recorded mutations are stored.
32
+ */
33
+ flush(): Promise<void>;
34
+ /**
35
+ * Observe committed runtime mutations. Image seeding is deliberately silent.
36
+ * @param listener - Consumer called after each successful mutation.
37
+ * @returns A disposer that prevents future calls.
38
+ */
39
+ subscribe(listener: VfsMutationListener): () => void;
40
+ /** Publish after state changes; one faulty observer cannot roll back a write. */
41
+ private publish;
42
+ /** Promise face mirroring `node:fs/promises` for the methods the roster uses. */
43
+ readonly promises: {
44
+ readFile: (path: string, options?: VfsReadOptions) => Promise<string | Uint8Array>;
45
+ writeFile: (path: string, data: string | Uint8Array, options?: VfsWriteOptions) => Promise<void>;
46
+ appendFile: (path: string, data: string | Uint8Array) => Promise<void>;
47
+ mkdir: (path: string, options?: {
48
+ recursive?: boolean;
49
+ mode?: number;
50
+ }) => Promise<string | undefined>;
51
+ readdir: (path: string, options?: {
52
+ withFileTypes?: boolean;
53
+ }) => Promise<string[] & VfsDirent[]>;
54
+ stat: (path: string, options?: VfsStatOptions) => Promise<VfsStats | VfsBigIntStats>;
55
+ lstat: (path: string, options?: VfsStatOptions) => Promise<VfsStats | VfsBigIntStats>;
56
+ realpath: (path: string) => Promise<string>;
57
+ rename: (from: string, to: string) => Promise<void>;
58
+ unlink: (path: string) => Promise<void>;
59
+ rm: (path: string, options?: {
60
+ recursive?: boolean;
61
+ force?: boolean;
62
+ }) => Promise<void>;
63
+ mkdtemp: (prefix: string) => Promise<string>;
64
+ link: (existing: string, next: string) => Promise<void>;
65
+ truncate: (path: string, length?: number) => Promise<void>;
66
+ chmod: (path: string, mode: number) => Promise<void>;
67
+ opendir: (path: string) => Promise<VfsDir>;
68
+ open: (path: string, flags?: string, mode?: number) => Promise<VfsFileHandle>;
69
+ /** Resolves for any existing path: the VFS grants read and write to everything it holds. */
70
+ access: (path: string) => Promise<void>;
71
+ };
72
+ /** @returns Absolute path with no trailing separator. */
73
+ private key;
74
+ /**
75
+ * Read a file.
76
+ * @param path - File path.
77
+ * @param options - `'utf8'` or `{encoding}` for text; omitted for bytes.
78
+ * @returns Text or a copy-free view of the stored bytes.
79
+ */
80
+ readFileSync(path: string, options?: VfsReadOptions): string | Uint8Array;
81
+ /**
82
+ * Report whether a path exists.
83
+ * @param path - Path to test.
84
+ * @returns True for files and directories.
85
+ */
86
+ existsSync(path: string): boolean;
87
+ /**
88
+ * Stat a path.
89
+ * @param path - Path to stat.
90
+ * @param options - `bigint` selects the BigInt stats Node returns for it.
91
+ * @returns Stats for the file or directory.
92
+ */
93
+ statSync(path: string, options?: VfsStatOptions): VfsStats | VfsBigIntStats;
94
+ /** @returns Stats in the plain shape, for internal callers that read `size`/`mtimeMs`. */
95
+ private plainStats;
96
+ /** @returns The stable identity of an existing path, assigning one on first observation. */
97
+ private identityOf;
98
+ /** @returns The inode-like identity retained by a file node across names. */
99
+ private identityOfFile;
100
+ /** @returns The number of names currently linked to one file node. */
101
+ private fileLinkCount;
102
+ /** Add one map name, promoting the rare hard-link case to a Set. */
103
+ private addFilePath;
104
+ /** Remove one map name, collapsing a remaining single link back to a string. */
105
+ private removeFilePath;
106
+ /** Set one file-map entry while maintaining both nodes' reverse path indexes. */
107
+ private setFile;
108
+ /** Delete one file-map entry while retaining an unlinked node held by a descriptor. */
109
+ private deleteFile;
110
+ /** Publish one linked name after a content or metadata write. */
111
+ private publishFilePath;
112
+ /** Publish a content or metadata write for every hard link to one node. */
113
+ private publishFile;
114
+ /** Replace bytes on one file identity and notify all linked paths. */
115
+ private replaceFile;
116
+ /** Write at one offset, zero-filling any gap. */
117
+ private writeFileNode;
118
+ /** Resize one file identity and notify all linked paths. */
119
+ private truncateFile;
120
+ /** Change one file identity's permission bits and notify every linked path. */
121
+ private chmodFile;
122
+ /** @returns Plain stats for an open file, including after its last name is removed. */
123
+ private fileStats;
124
+ /** @returns BigInt stats for an open file, including its device and inode identity. */
125
+ private fileBigIntStats;
126
+ /** Forget removed directory identities, so recreated paths report new ones. */
127
+ private forgetIdentity;
128
+ /**
129
+ * Modification time for a write, strictly after the entry's previous one.
130
+ *
131
+ * The clock has millisecond resolution and these writes are in memory, so two
132
+ * revisions of one file routinely land in the same millisecond. The filesystem
133
+ * service's stale-write guard compares timestamps, so an equal one would let a
134
+ * stale overwrite through.
135
+ * @param target - Normalized path being written.
136
+ * @returns Now, or one millisecond past the entry's current time.
137
+ */
138
+ private touch;
139
+ /** @returns A modification time strictly newer than one file node's current value. */
140
+ private touchNode;
141
+ /** Advance a directory's mtime after its immediate children change. */
142
+ private touchDirectory;
143
+ /**
144
+ * List a directory.
145
+ * @param path - Directory path.
146
+ * @param options - `withFileTypes` returns {@link VfsDirent} objects instead of names.
147
+ * @returns Immediate entry names, or directory entries.
148
+ */
149
+ readdirSync(path: string, options?: {
150
+ withFileTypes?: boolean;
151
+ }): string[] & VfsDirent[];
152
+ /** @returns Directory entry for one child of `directory`. */
153
+ private direntOf;
154
+ /**
155
+ * Resolve a path; the VFS has no symlinks, so this only normalizes.
156
+ * @param path - Path to resolve.
157
+ * @returns Absolute path.
158
+ */
159
+ realpathSync(path: string): string;
160
+ /**
161
+ * Create a directory.
162
+ * @param path - Directory path.
163
+ * @param options - `recursive` creates missing parents.
164
+ * @returns First created path when recursive, otherwise undefined.
165
+ */
166
+ mkdirSync(path: string, options?: {
167
+ recursive?: boolean;
168
+ mode?: number;
169
+ }): string | undefined;
170
+ /**
171
+ * Write a file, replacing existing contents.
172
+ * @param path - File path; its parent directory must exist.
173
+ * @param data - Text or bytes.
174
+ * @param options - `flag` `wx` refuses an existing file, `a` appends.
175
+ */
176
+ writeFileSync(path: string, data: string | Uint8Array, options?: VfsWriteOptions): void;
177
+ /**
178
+ * Open a directory; consumers enumerate entries or just prove it is one.
179
+ * @param path - Directory path.
180
+ * @returns Directory handle.
181
+ */
182
+ opendir(path: string): VfsDir;
183
+ /**
184
+ * Open a file handle.
185
+ * @param path - File path.
186
+ * @param flags - Node open flags; `r` requires the file, `wx` refuses an existing one.
187
+ * @param mode - Permission bits applied when the open creates the file.
188
+ * @returns File handle.
189
+ */
190
+ open(path: string, flags?: string, mode?: number): VfsFileHandle;
191
+ /**
192
+ * Open one synchronous descriptor over a stable file identity.
193
+ * @param path - File path.
194
+ * @param flags - Node open flags.
195
+ * @param mode - Permission bits applied only when a file is created.
196
+ * @returns An open file that survives path rename, replacement, and unlink.
197
+ */
198
+ openFileSync(path: string, flags?: string, mode?: number): VfsOpenFile;
199
+ /**
200
+ * Directory-handle members for metadata, durability, and release.
201
+ * `sync`/`datasync` settle an attached durable sink; an ephemeral filesystem
202
+ * resolves immediately and `close` releases nothing.
203
+ * @param target - Normalized path the handle was opened on.
204
+ * @returns Metadata plus the no-op durability and release calls.
205
+ */
206
+ private handleTail;
207
+ /**
208
+ * Append to a file, creating it when absent.
209
+ * @param path - File path.
210
+ * @param data - Text or bytes.
211
+ */
212
+ appendFileSync(path: string, data: string | Uint8Array): void;
213
+ /**
214
+ * Move a file or directory subtree.
215
+ * @param from - Source path.
216
+ * @param to - Destination path.
217
+ */
218
+ renameSync(from: string, to: string): void;
219
+ /**
220
+ * Give existing bytes a second name.
221
+ *
222
+ * Both names retain one file identity, so writes and metadata changes through
223
+ * either name remain visible through the other until that name is removed.
224
+ * @param existing - Source file path.
225
+ * @param next - Additional path; its parent must exist and it must be free.
226
+ */
227
+ linkSync(existing: string, next: string): void;
228
+ /**
229
+ * Shorten a file.
230
+ * @param path - File path.
231
+ * @param length - Byte length to keep; defaults to zero.
232
+ */
233
+ truncateSync(path: string, length?: number): void;
234
+ /**
235
+ * Change an entry's permission bits; stat reads back exactly what was set.
236
+ * @param path - File or directory path.
237
+ * @param mode - New permission bits (`0o777` mask).
238
+ */
239
+ chmodSync(path: string, mode: number): void;
240
+ /**
241
+ * Remove a file.
242
+ * @param path - File path.
243
+ */
244
+ unlinkSync(path: string): void;
245
+ /**
246
+ * Remove a file or directory.
247
+ * @param path - Path to remove.
248
+ * @param options - `recursive` removes subtrees, `force` ignores absence.
249
+ */
250
+ rmSync(path: string, options?: {
251
+ recursive?: boolean;
252
+ force?: boolean;
253
+ }): void;
254
+ /**
255
+ * Create a uniquely named directory beside `prefix`, as `fs.mkdtempSync` does.
256
+ * @param prefix - Path prefix; the suffix is appended without a separator.
257
+ * @returns The created directory path.
258
+ */
259
+ mkdtempSync(prefix: string): string;
260
+ /**
261
+ * Seed a file and its parent directories, for image loading and tests.
262
+ * @param path - File path.
263
+ * @param data - Text or bytes.
264
+ * @param options - Permission bits and modification time supplied by the image or durable store.
265
+ */
266
+ seed(path: string, data: string | Uint8Array, options?: VfsSeedOptions): void;
267
+ /**
268
+ * Create a directory and its parents.
269
+ * @param path - Directory path.
270
+ * @param options - Permission bits and modification time supplied by the image or durable store.
271
+ */
272
+ seedDirectory(path: string, options?: VfsSeedOptions): void;
273
+ /**
274
+ * Report what this filesystem holds, for the host's boot diagnostics.
275
+ * @returns File count, directory count, and total byte size.
276
+ */
277
+ usage(): {
278
+ files: number;
279
+ directories: number;
280
+ bytes: number;
281
+ };
282
+ }
283
+ /**
284
+ * Mount a tar image produced by the build-time collector.
285
+ *
286
+ * Entry names are relative to `root` (`node_modules/...`, `config/cordis.yml`);
287
+ * an absolute entry name is a collector defect and fails loud. File contents
288
+ * stay views into `image` — nothing is copied at mount time.
289
+ * @param image - The ustar archive, as `inflateImage` produces it from the fetched image.
290
+ * @param root - Virtual root the entries mount under.
291
+ * @param vfs - Filesystem to fill; a fresh one by default.
292
+ * @returns The filled filesystem.
293
+ */
294
+ export declare function loadVfsImage(image: Uint8Array, root?: string, vfs?: MemoryVfs): MemoryVfs;
295
+ /**
296
+ * Apply one ordered data overlay to an already mounted base image.
297
+ *
298
+ * Overlay entries may replace files only under the layout's data directories;
299
+ * module code, configuration, and the lowering manifest cannot be shadowed.
300
+ * Paths containing traversal segments are refused before normalization. Later
301
+ * overlays win for files, while file/directory type conflicts fail loud.
302
+ * @param image - Uncompressed ustar overlay archive.
303
+ * @param root - Virtual root shared with the base image.
304
+ * @param vfs - Mounted filesystem to update.
305
+ * @returns The same filesystem after applying the overlay.
306
+ */
307
+ export declare function loadVfsOverlay(image: Uint8Array, root: string, vfs: MemoryVfs): MemoryVfs;
308
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Virtual root of the worker host's in-memory filesystem. Kept
3
+ * in one module so the process shim, the path/os shims, and the VFS image
4
+ * collector cannot drift apart.
5
+ */
6
+ /** Virtual filesystem root; `process.cwd()` and every absolute path start here. */
7
+ export declare const DSH_ROOT = "/dsh";
8
+ /** `$DSH_HOME`: durable-state directory inside the image. */
9
+ export declare const DSH_HOME = "/dsh/home";
10
+ /** Flat, symlink-free package tree resolved by the worker module loader. */
11
+ export declare const DSH_NODE_MODULES = "/dsh/node_modules";
12
+ /** Directory holding the composed cordis.yml and the agent-preset tree. */
13
+ export declare const DSH_CONFIG = "/dsh/config";
14
+ /** Default (empty) workspace directory. */
15
+ export declare const DSH_WORKSPACE = "/dsh/workspace";
16
+ /** Temporary directory reported by `os.tmpdir()`. */
17
+ export declare const DSH_TMP = "/dsh/tmp";
18
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Uncompressed ustar archive: the VFS image format. One fetch delivers the
3
+ * whole tree, and the reader hands out subarray views into the fetched buffer,
4
+ * so mounting copies nothing and no inflate step runs inside the worker.
5
+ *
6
+ * Hand-rolled on purpose: both sides need synchronous in-memory operation and
7
+ * the reader ships inside the worker bundle, where the streaming tar packages
8
+ * would drag Node stream shims back in. The subset is plain ustar — regular
9
+ * files and directories, names up to 255 bytes via the name-prefix split — and
10
+ * anything outside it fails loud on either side.
11
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/storage/tar
12
+ */
13
+ /** One archive entry; a directory carries empty bytes and a trailing-slash name. */
14
+ export interface TarEntry {
15
+ readonly name: string;
16
+ readonly bytes: Uint8Array;
17
+ readonly directory: boolean;
18
+ /** Permission bits from the header's mode field (`0o777` mask). */
19
+ readonly mode: number;
20
+ }
21
+ /**
22
+ * Pack entries into one uncompressed ustar archive.
23
+ *
24
+ * Entries keep their given order; names ending in a slash become directory
25
+ * entries. Contents are written verbatim — compression belongs to the HTTP
26
+ * transport, not to the archive.
27
+ * @param files - Entry name to content bytes.
28
+ * @returns The archive bytes.
29
+ */
30
+ export declare function packTar(files: Readonly<Record<string, Uint8Array>>): Uint8Array;
31
+ /**
32
+ * Parse an uncompressed ustar archive.
33
+ *
34
+ * File bytes are subarray views into `archive`, not copies; callers own the
35
+ * aliasing. Entry kinds outside the written subset (links, PAX extensions)
36
+ * fail loud instead of being skipped.
37
+ * @param archive - Archive bytes.
38
+ * @returns Entries in archive order.
39
+ */
40
+ export declare function parseTar(archive: Uint8Array): TarEntry[];
41
+ //# sourceMappingURL=tar.d.ts.map
@@ -0,0 +1,279 @@
1
+ /**
2
+ * Filesystem interfaces shared by every VFS backend. The shipped implementation
3
+ * is in memory; browser persistence hydrates it and consumes its committed
4
+ * mutation stream. Errors carry Node's `code` values because roster plugins
5
+ * branch on them (`ENOENT` for optional files, `EACCES` for read-only trees).
6
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/storage/types
7
+ */
8
+ /** Encodings the VFS accepts where Node accepts any `BufferEncoding`. */
9
+ export type VfsEncoding = 'utf8' | 'utf-8';
10
+ /** Read options accepted by both the sync and promise faces. */
11
+ export type VfsReadOptions = VfsEncoding | {
12
+ encoding?: VfsEncoding | null;
13
+ } | null | undefined;
14
+ /** Node-compatible error with a `code`, as roster plugins expect. */
15
+ export interface VfsError extends Error {
16
+ code: string;
17
+ path: string;
18
+ syscall: string;
19
+ }
20
+ /** Subset of `fs.Stats` the roster reads. */
21
+ export interface VfsStats {
22
+ readonly size: number;
23
+ /** Stable file identity across rename and hard links; recreation receives another value. */
24
+ readonly ino: number;
25
+ readonly mtimeMs: number;
26
+ readonly ctimeMs: number;
27
+ readonly atimeMs: number;
28
+ readonly birthtimeMs: number;
29
+ readonly mtime: Date;
30
+ readonly mode: number;
31
+ isFile(): boolean;
32
+ isDirectory(): boolean;
33
+ isSymbolicLink(): boolean;
34
+ isFIFO(): boolean;
35
+ isSocket(): boolean;
36
+ isBlockDevice(): boolean;
37
+ isCharacterDevice(): boolean;
38
+ }
39
+ /**
40
+ * Stats as Node returns them under `{ bigint: true }`.
41
+ *
42
+ * The filesystem service (`dsh-fs-local`) stats every target this way and then
43
+ * does BigInt arithmetic on `mode` and builds its version token from
44
+ * `dev:ino:size:mtimeNs:ctimeNs`, so these fields are load-bearing rather than
45
+ * decorative: a number-valued `mode` here fails the whole read as a type error,
46
+ * and a constant `ino`/`mtimeNs` would make the service's stale-write guard
47
+ * unable to tell two revisions apart.
48
+ */
49
+ export interface VfsBigIntStats {
50
+ readonly size: bigint;
51
+ readonly mode: bigint;
52
+ /** One virtual device holds the whole image. */
53
+ readonly dev: bigint;
54
+ /** File identity retained across rename and hard links; recreation gets a new one. */
55
+ readonly ino: bigint;
56
+ readonly nlink: bigint;
57
+ readonly mtimeMs: bigint;
58
+ readonly mtimeNs: bigint;
59
+ readonly ctimeMs: bigint;
60
+ readonly ctimeNs: bigint;
61
+ readonly atimeMs: bigint;
62
+ readonly atimeNs: bigint;
63
+ readonly birthtimeMs: bigint;
64
+ readonly birthtimeNs: bigint;
65
+ readonly mtime: Date;
66
+ readonly ctime: Date;
67
+ readonly atime: Date;
68
+ readonly birthtime: Date;
69
+ isFile(): boolean;
70
+ isDirectory(): boolean;
71
+ isSymbolicLink(): boolean;
72
+ isFIFO(): boolean;
73
+ isSocket(): boolean;
74
+ isBlockDevice(): boolean;
75
+ isCharacterDevice(): boolean;
76
+ }
77
+ /** Stat option Node reads; `bigint` selects {@link VfsBigIntStats}. */
78
+ export interface VfsStatOptions {
79
+ readonly bigint?: boolean;
80
+ }
81
+ /** Write options the roster passes; `flag` decides create and truncate behavior. */
82
+ export interface VfsWriteOptions {
83
+ readonly encoding?: VfsEncoding | null;
84
+ readonly mode?: number;
85
+ readonly flag?: string;
86
+ }
87
+ /** Explicit metadata for image or durable-store hydration. */
88
+ export interface VfsSeedOptions {
89
+ readonly mode?: number;
90
+ readonly mtimeMs?: number;
91
+ }
92
+ /** Directory entry as `readdir` with `withFileTypes` reports it. */
93
+ export interface VfsDirent {
94
+ readonly name: string;
95
+ readonly parentPath: string;
96
+ isFile(): boolean;
97
+ isDirectory(): boolean;
98
+ isSymbolicLink(): boolean;
99
+ }
100
+ /** Directory handle returned by `opendir`; consumers only enumerate and close. */
101
+ export interface VfsDir {
102
+ readonly path: string;
103
+ close(): Promise<void>;
104
+ read(): Promise<{
105
+ name: string;
106
+ } | null>;
107
+ [Symbol.asyncIterator](): AsyncGenerator<{
108
+ name: string;
109
+ isFile(): boolean;
110
+ isDirectory(): boolean;
111
+ }>;
112
+ }
113
+ /** File handle returned by `open`; the roster writes, syncs, and closes. */
114
+ export interface VfsFileHandle {
115
+ write(data: string | Uint8Array): Promise<{
116
+ bytesWritten: number;
117
+ }>;
118
+ writeFile(data: string | Uint8Array): Promise<void>;
119
+ readFile(options?: VfsReadOptions): Promise<string | Uint8Array>;
120
+ truncate(length?: number): Promise<void>;
121
+ chmod(mode: number): Promise<void>;
122
+ stat(options?: VfsStatOptions): Promise<VfsStats | VfsBigIntStats>;
123
+ sync(): Promise<void>;
124
+ datasync(): Promise<void>;
125
+ close(): Promise<void>;
126
+ }
127
+ /** Open-file identity used by synchronous Node-style descriptors. */
128
+ export interface VfsOpenFile {
129
+ /** Whether reads are allowed by the flags used at open time. */
130
+ readonly readable: boolean;
131
+ /** Whether writes and truncation are allowed by the flags used at open time. */
132
+ readonly writable: boolean;
133
+ /** Whether each write targets the current end of the opened file. */
134
+ readonly append: boolean;
135
+ /**
136
+ * Read bytes from the opened file identity.
137
+ * @param position - Absolute byte offset.
138
+ * @param length - Maximum byte count.
139
+ * @returns A view of the available bytes.
140
+ */
141
+ read(position: number, length: number): Uint8Array;
142
+ /**
143
+ * Write bytes to the opened file identity.
144
+ * @param position - Absolute byte offset, ignored for append descriptors.
145
+ * @param data - Bytes to write.
146
+ * @returns Number of bytes written.
147
+ */
148
+ write(position: number, data: Uint8Array): number;
149
+ /**
150
+ * Resize the opened file, zero-filling growth.
151
+ * @param length - Target byte length.
152
+ */
153
+ truncate(length: number): void;
154
+ /** Change permission bits on the opened file identity. */
155
+ chmod(mode: number): void;
156
+ /**
157
+ * Read metadata from the opened file identity.
158
+ * @returns Current file metadata, including after rename or unlink.
159
+ */
160
+ stat(): VfsStats;
161
+ /**
162
+ * Read BigInt metadata from the opened file identity.
163
+ * @returns Current file metadata, including device and inode identity.
164
+ */
165
+ statBigInt(): VfsBigIntStats;
166
+ }
167
+ /**
168
+ * One completed change to the authoritative in-memory filesystem.
169
+ *
170
+ * A durable mirror receives the post-write bytes, virtual permission bits, and optional append offset;
171
+ * live watchers use `entryChanged` to distinguish directory-entry replacement
172
+ * from content writes. Rename is represented as source removal plus complete
173
+ * destination mkdir/write records, so a sink never receives a path without the
174
+ * state needed to materialize it.
175
+ */
176
+ export type VfsMutation = {
177
+ readonly kind: 'write';
178
+ readonly path: string;
179
+ readonly bytes: Uint8Array;
180
+ readonly mode: number;
181
+ readonly entryChanged: boolean;
182
+ readonly appendedFrom?: number;
183
+ } | {
184
+ readonly kind: 'mkdir';
185
+ readonly path: string;
186
+ readonly mode: number;
187
+ } | {
188
+ readonly kind: 'remove';
189
+ readonly path: string;
190
+ } | {
191
+ readonly kind: 'chmod';
192
+ readonly path: string;
193
+ readonly mode: number;
194
+ };
195
+ /** Receives one committed VFS mutation. */
196
+ export type VfsMutationListener = (mutation: VfsMutation) => void;
197
+ /** Durable observer attached to the synchronous VFS. */
198
+ export interface VfsMutationSink {
199
+ /**
200
+ * Record one completed mutation without delaying its caller.
201
+ * @param mutation - Post-commit state to mirror.
202
+ */
203
+ record(mutation: VfsMutation): void;
204
+ /**
205
+ * Settle all previously recorded mutations.
206
+ * Implementations report persistence failures and stop mirroring rather than
207
+ * rejecting, because the in-memory mutation has already committed.
208
+ * @returns A promise that resolves when the sink has no pending work.
209
+ */
210
+ flush(): Promise<void>;
211
+ }
212
+ /** Synchronous filesystem used by the worker's Node compatibility modules. */
213
+ export interface Vfs {
214
+ readonly promises: {
215
+ readFile(path: string, options?: VfsReadOptions): Promise<string | Uint8Array>;
216
+ writeFile(path: string, data: string | Uint8Array, options?: VfsWriteOptions): Promise<void>;
217
+ appendFile(path: string, data: string | Uint8Array): Promise<void>;
218
+ mkdir(path: string, options?: {
219
+ recursive?: boolean;
220
+ mode?: number;
221
+ }): Promise<string | undefined>;
222
+ readdir(path: string, options?: {
223
+ withFileTypes?: boolean;
224
+ }): Promise<string[] & VfsDirent[]>;
225
+ stat(path: string, options?: VfsStatOptions): Promise<VfsStats | VfsBigIntStats>;
226
+ lstat(path: string, options?: VfsStatOptions): Promise<VfsStats | VfsBigIntStats>;
227
+ realpath(path: string): Promise<string>;
228
+ rename(from: string, to: string): Promise<void>;
229
+ unlink(path: string): Promise<void>;
230
+ rm(path: string, options?: {
231
+ recursive?: boolean;
232
+ force?: boolean;
233
+ }): Promise<void>;
234
+ mkdtemp(prefix: string): Promise<string>;
235
+ link(existing: string, next: string): Promise<void>;
236
+ truncate(path: string, length?: number): Promise<void>;
237
+ chmod(path: string, mode: number): Promise<void>;
238
+ opendir(path: string): Promise<VfsDir>;
239
+ open(path: string, flags?: string, mode?: number): Promise<VfsFileHandle>;
240
+ access(path: string): Promise<void>;
241
+ };
242
+ readFileSync(path: string, options?: VfsReadOptions): string | Uint8Array;
243
+ existsSync(path: string): boolean;
244
+ statSync(path: string, options?: VfsStatOptions): VfsStats | VfsBigIntStats;
245
+ readdirSync(path: string, options?: {
246
+ withFileTypes?: boolean;
247
+ }): string[] & VfsDirent[];
248
+ realpathSync(path: string): string;
249
+ mkdirSync(path: string, options?: {
250
+ recursive?: boolean;
251
+ mode?: number;
252
+ }): string | undefined;
253
+ writeFileSync(path: string, data: string | Uint8Array, options?: VfsWriteOptions): void;
254
+ appendFileSync(path: string, data: string | Uint8Array): void;
255
+ renameSync(from: string, to: string): void;
256
+ linkSync(existing: string, next: string): void;
257
+ truncateSync(path: string, length?: number): void;
258
+ chmodSync(path: string, mode: number): void;
259
+ unlinkSync(path: string): void;
260
+ rmSync(path: string, options?: {
261
+ recursive?: boolean;
262
+ force?: boolean;
263
+ }): void;
264
+ mkdtempSync(prefix: string): string;
265
+ /** Open and retain one file identity until its Node descriptor closes. */
266
+ openFileSync(path: string, flags?: string, mode?: number): VfsOpenFile;
267
+ seed(path: string, data: string | Uint8Array, options?: VfsSeedOptions): void;
268
+ seedDirectory(path: string, options?: VfsSeedOptions): void;
269
+ usage(): {
270
+ files: number;
271
+ directories: number;
272
+ bytes: number;
273
+ };
274
+ /** Register one observer and return its synchronous disposer. */
275
+ subscribe(listener: VfsMutationListener): () => void;
276
+ /** Settle the attached durable mutation sink, if any. */
277
+ flush(): Promise<void>;
278
+ }
279
+ //# sourceMappingURL=types.d.ts.map