@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,43 @@
1
+ /**
2
+ * The in-host filesystem for shell runs: {@link ShellFileSystem} straight over
3
+ * the mounted VFS, plus the path and diagnostic helpers every program shares.
4
+ *
5
+ * This implementation answers from memory. A command running in its own
6
+ * worker uses the message-backed one (`./process/child.ts`), which this one
7
+ * serves from the host side.
8
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/fs-access
9
+ */
10
+ import type { VfsError } from '../storage/types.ts';
11
+ import type { ShellFileSystem } from './types.ts';
12
+ /**
13
+ * Resolve one shell word into an absolute VFS path.
14
+ * @param cwd - the shell's working directory.
15
+ * @param path - absolute or relative path as the command line spelled it.
16
+ * @returns the absolute normalized path.
17
+ */
18
+ export declare function resolveIn(cwd: string, path: string): string;
19
+ /**
20
+ * Restate a filesystem failure the way a shell utility reports it, so the model
21
+ * reads `cat: /dsh/none: No such file or directory` instead of a Node error
22
+ * string.
23
+ * @param program - the utility's name, used as the message prefix.
24
+ * @param path - the path the utility was working on.
25
+ * @param error - the failure the filesystem raised.
26
+ * @returns the single-line diagnostic, without a trailing newline.
27
+ */
28
+ export declare function describeFailure(program: string, path: string, error: unknown): string;
29
+ /**
30
+ * Build a Node-shaped filesystem error, for the conditions this layer detects
31
+ * itself and for the worker transport, which can carry a code but not a class.
32
+ * @param code - the Node error code (`ENOENT`, `EISDIR`, …).
33
+ * @param syscall - the operation that failed.
34
+ * @param path - the path it failed on.
35
+ * @returns the error to throw.
36
+ */
37
+ export declare function filesystemError(code: string, syscall: string, path: string): VfsError;
38
+ /**
39
+ * The filesystem backed by the VFS mounted in this thread.
40
+ * @returns the in-host {@link ShellFileSystem}.
41
+ */
42
+ export declare function hostFileSystem(): ShellFileSystem;
43
+ //# sourceMappingURL=fs-access.d.ts.map
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The interpreter: it walks the parsed command line and runs the command table
3
+ * against the VFS. Structure (`;` `&` `|` `|&` `&&` `||`, subshells, groups,
4
+ * redirections, prefix assignments) is honored here; what a command *does*
5
+ * belongs to its program in `./programs/`.
6
+ *
7
+ * Output is text, not streams: every program is a JavaScript function that
8
+ * returns before the next one runs, so a pipeline hands a string along instead
9
+ * of plumbing byte streams a browser worker has no way to schedule between.
10
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/interpret
11
+ */
12
+ import type { ShellFileSystem, ShellRunOutcome } from './types.ts';
13
+ /** Everything one `bash -c` invocation needs. */
14
+ export interface ShellRunOptions {
15
+ /** Working directory the line starts in. */
16
+ cwd: string;
17
+ /** Environment the line starts with. */
18
+ env: Record<string, string>;
19
+ /** Standard input contents; absent means empty. */
20
+ stdin?: string | undefined;
21
+ /** Cancellation: an aborted line stops before its next command. */
22
+ signal?: AbortSignal | undefined;
23
+ /**
24
+ * The filesystem this run acts on; defaults to the VFS mounted in this
25
+ * thread. A run inside a process worker passes the message-backed one.
26
+ */
27
+ fs?: ShellFileSystem | undefined;
28
+ /**
29
+ * Called with each write as it happens, before the run settles. The returned
30
+ * outcome still carries the complete text; this only lets a caller that
31
+ * reports progress (a background job's incremental reads) see output while
32
+ * the line is still running.
33
+ */
34
+ onOutput?: ((stream: 'stdout' | 'stderr', text: string) => void) | undefined;
35
+ }
36
+ /**
37
+ * Run one shell command line to completion.
38
+ * @param source - the command source, exactly as `bash -c` would receive it.
39
+ * @param options - starting directory, environment, standard input, cancellation, filesystem, output callback.
40
+ * @returns the exit status and the complete standard output and standard error.
41
+ */
42
+ export declare function runShellCommand(source: string, options: ShellRunOptions): Promise<ShellRunOutcome>;
43
+ /**
44
+ * Run one program directly, without a command line to parse.
45
+ *
46
+ * This is the path for an argv the caller already has in pieces — a spawn that
47
+ * names a program instead of handing `bash` a script — so nothing re-quotes
48
+ * words that were never quoted in the first place.
49
+ * @param argv - the program name at index 0, then its arguments.
50
+ * @param options - starting directory, environment, standard input, cancellation, filesystem, output callback.
51
+ * @returns the exit status and the complete standard output and standard error.
52
+ */
53
+ export declare function runShellProgram(argv: readonly string[], options: ShellRunOptions): Promise<ShellRunOutcome>;
54
+ //# sourceMappingURL=interpret.d.ts.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The process worker's own half: a fresh worker that received a
3
+ * {@link ShellStartFrame} runs one command here and then closes.
4
+ *
5
+ * It mounts no VFS image, boots no Cordis tree, and loads no plugins — the
6
+ * only thing it shares with the host worker is the bundle it was started from.
7
+ * Its filesystem is the host's, reached by message.
8
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/process/child
9
+ */
10
+ import type { FromProcessFrame, ShellStartFrame } from './protocol.ts';
11
+ /** The messaging face this module needs from a worker scope. */
12
+ export interface ProcessScope {
13
+ postMessage(frame: FromProcessFrame): void;
14
+ addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
15
+ close(): void;
16
+ }
17
+ /**
18
+ * Run one command as this worker's whole purpose, then close.
19
+ *
20
+ * Output is forwarded as it is written, so a caller reading a background job
21
+ * sees progress before the command settles.
22
+ * @param start - the frame that named the command, its directory, and its input.
23
+ * @param scope - the worker scope to message through (`self`).
24
+ */
25
+ export declare function runShellProcess(start: ShellStartFrame, scope: ProcessScope): void;
26
+ //# sourceMappingURL=child.d.ts.map
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Starting and supervising shell processes from the host worker.
3
+ *
4
+ * A process is a Web Worker started from this same bundle, told by its first
5
+ * frame to be a shell process rather than a host. That is what buys real
6
+ * process semantics in a browser: the command runs off the host's thread, and
7
+ * `terminate()` stops it even mid-loop — the one thing a cooperative in-thread
8
+ * interpreter can never do.
9
+ *
10
+ * Where no `Worker` constructor exists (a Node test host), the same command
11
+ * runs inline on this thread. Everything except preemption behaves the same,
12
+ * and the difference is named rather than hidden: {@link RunningProcess.destroy}
13
+ * can only ask an inline command to stop.
14
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/process/host
15
+ */
16
+ import type { ShellFileSystem } from '../types.ts';
17
+ import { runShellProcess } from './child.ts';
18
+ import type { ProcessScope } from './child.ts';
19
+ /** What the caller must supply to start one process. */
20
+ export interface ProcessStartOptions {
21
+ /** Command source for `bash -c`, or undefined when `argv` names a program. */
22
+ script?: string | undefined;
23
+ /** The program and its arguments. */
24
+ argv: readonly string[];
25
+ /** Working directory the command starts in. */
26
+ cwd: string;
27
+ /** Environment the command starts with. */
28
+ env: Record<string, string>;
29
+ /** Everything on standard input. */
30
+ stdin: string;
31
+ /** Receives output as it is produced. */
32
+ onOutput: (stream: 'stdout' | 'stderr', text: string) => void;
33
+ /** Receives the settled status exactly once. */
34
+ onExit: (code: number) => void;
35
+ /** The filesystem the command acts on; defaults to the mounted VFS. */
36
+ fs?: ShellFileSystem | undefined;
37
+ }
38
+ /** A started command, from the host's side. */
39
+ export interface RunningProcess {
40
+ /** Ask the command to stop at its next command boundary (the `SIGTERM` rung). */
41
+ interrupt(): void;
42
+ /**
43
+ * Stop the command now (the `SIGKILL` rung). A worker-backed process dies
44
+ * whatever it was doing; an inline one can only be asked, because nothing
45
+ * can preempt a synchronous loop on its own thread.
46
+ */
47
+ destroy(): void;
48
+ }
49
+ /**
50
+ * Start one command.
51
+ * @param options - the command, its environment, and the sinks for its output and status.
52
+ * @returns the handle the process table signals through.
53
+ */
54
+ export declare function startProcess(options: ProcessStartOptions): RunningProcess;
55
+ /** Re-exported for the worker entry, which decides its role from the first frame. */
56
+ export { runShellProcess };
57
+ export type { ProcessScope };
58
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1,33 @@
1
+ import type { ShellFileSystem } from '../types.ts';
2
+ import type { VirtualExecutable } from './virtual-executables.ts';
3
+ /** Parsed invocation of the native launcher's unchanged argv grammar. */
4
+ export type LandlockInvocation = {
5
+ readonly kind: 'probe';
6
+ } | {
7
+ readonly kind: 'run';
8
+ readonly readOnly: readonly string[];
9
+ readonly readWrite: readonly string[];
10
+ readonly argv: readonly string[];
11
+ };
12
+ /** Launcher-owned failure; callers print its message with the `landlock-run:` prefix. */
13
+ export declare class LandlockLauncherError extends Error {
14
+ }
15
+ /**
16
+ * Parse the native launcher's argv grammar.
17
+ * @param args - Arguments after the launcher executable.
18
+ * @returns A probe or confined-run request.
19
+ */
20
+ export declare function parseLandlockArguments(args: readonly string[]): LandlockInvocation;
21
+ /**
22
+ * Validate grant roots and create one process-local filesystem guard.
23
+ * @param base - Host-side VFS adapter all permitted calls delegate to.
24
+ * @param invocation - Parsed confined-run request.
25
+ * @param cwd - Launcher's working directory for relative grant paths.
26
+ * @returns A filesystem enforcing only this invocation's grants.
27
+ */
28
+ export declare function landlockFileSystem(base: ShellFileSystem, invocation: Extract<LandlockInvocation, {
29
+ kind: 'run';
30
+ }>, cwd: string): Promise<ShellFileSystem>;
31
+ /** Virtual executable implementing the native launcher's CLI over VFS grants. */
32
+ export declare const LANDLOCK_EXECUTABLE: VirtualExecutable;
33
+ //# sourceMappingURL=landlock.d.ts.map
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The frames a shell process and its host exchange.
3
+ *
4
+ * A command runs in its own Web Worker, which owns no filesystem: the VFS
5
+ * stays in the host worker and every read or write is a request on this
6
+ * channel. Blocking the child on a reply is impossible here (that would need
7
+ * `SharedArrayBuffer`, which requires a cross-origin isolation this deployment
8
+ * cannot have), so the filesystem face is asynchronous end to end.
9
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/process/protocol
10
+ */
11
+ /** The first frame a process worker receives; it also selects its role. */
12
+ export interface ShellStartFrame {
13
+ t: 'shell-start';
14
+ /** Command source for `bash -c`, or undefined when `argv` names a program directly. */
15
+ script?: string | undefined;
16
+ /** The program and arguments, used when `script` is absent. */
17
+ argv: readonly string[];
18
+ /** Working directory the command starts in. */
19
+ cwd: string;
20
+ /** Environment the command starts with. */
21
+ env: Record<string, string>;
22
+ /** Everything on standard input. */
23
+ stdin: string;
24
+ }
25
+ /** Output produced by the command, forwarded as it is written. */
26
+ export interface ShellOutputFrame {
27
+ t: 'shell-out';
28
+ stream: 'stdout' | 'stderr';
29
+ text: string;
30
+ }
31
+ /** The command settled; the process worker closes itself right after. */
32
+ export interface ShellExitFrame {
33
+ t: 'shell-exit';
34
+ code: number;
35
+ }
36
+ /** A signal the command is asked to honor (the terminate ladder's first rung). */
37
+ export interface ShellSignalFrame {
38
+ t: 'shell-signal';
39
+ }
40
+ /** Filesystem operations a process worker can ask its host to perform. */
41
+ export type FilesystemOperation = 'stat' | 'list' | 'readText' | 'writeText' | 'mkdir' | 'remove' | 'rename';
42
+ /** One filesystem call, awaiting its reply by `id`. */
43
+ export interface FilesystemCallFrame {
44
+ t: 'fs-call';
45
+ id: number;
46
+ op: FilesystemOperation;
47
+ args: readonly unknown[];
48
+ }
49
+ /**
50
+ * One filesystem reply. A failure carries the Node error `code` because the
51
+ * utilities branch on it (`ENOENT` prints "No such file or directory"), and an
52
+ * Error instance does not survive structured cloning with its class.
53
+ */
54
+ export interface FilesystemReplyFrame {
55
+ t: 'fs-reply';
56
+ id: number;
57
+ value?: unknown;
58
+ failure?: {
59
+ code?: string | undefined;
60
+ message: string;
61
+ };
62
+ }
63
+ /** Everything the host sends to a process worker. */
64
+ export type ToProcessFrame = ShellStartFrame | ShellSignalFrame | FilesystemReplyFrame;
65
+ /** Everything a process worker sends to its host. */
66
+ export type FromProcessFrame = ShellOutputFrame | ShellExitFrame | FilesystemCallFrame;
67
+ /**
68
+ * Whether a message is the frame that turns a fresh worker into a shell
69
+ * process. The host worker's entry reads this to pick its role.
70
+ * @param data - the raw message payload.
71
+ * @returns true when the payload starts a shell process.
72
+ */
73
+ export declare function isShellStartFrame(data: unknown): data is ShellStartFrame;
74
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1,49 @@
1
+ import type { ShellFileSystem } from '../types.ts';
2
+ /** Completed virtual executable invocation. */
3
+ export interface VirtualExecutableExit {
4
+ readonly kind: 'exit';
5
+ readonly exitCode: number;
6
+ readonly stdout: string;
7
+ readonly stderr: string;
8
+ }
9
+ /** Invocation delegated to the normal Worker command runner after preparation. */
10
+ export interface VirtualExecutableDelegate {
11
+ readonly kind: 'delegate';
12
+ readonly argv: readonly string[];
13
+ readonly filesystem: ShellFileSystem;
14
+ readonly missingExecutable: VirtualExecutableExit;
15
+ }
16
+ /** Result of preparing an asynchronous virtual executable invocation. */
17
+ export type VirtualExecutablePreparation = VirtualExecutableExit | VirtualExecutableDelegate;
18
+ /** Result available to the synchronous child-process face. */
19
+ export type VirtualExecutableSyncResult = VirtualExecutableExit | {
20
+ readonly kind: 'asynchronous';
21
+ };
22
+ /** One executable implemented by the Worker instead of an operating-system binary. */
23
+ export interface VirtualExecutable {
24
+ /** Platform executable name, independent of package-manager installation path. */
25
+ readonly name: string;
26
+ /**
27
+ * Prepare an invocation or complete it without entering the command runner.
28
+ * @param args - Arguments after the executable path.
29
+ * @param context - Working directory and ambient Worker filesystem.
30
+ * @returns The completed result or delegated command and filesystem.
31
+ */
32
+ prepare(args: readonly string[], context: {
33
+ readonly cwd: string;
34
+ readonly filesystem: ShellFileSystem;
35
+ }): Promise<VirtualExecutablePreparation>;
36
+ /**
37
+ * Handle the subset that can complete synchronously.
38
+ * @param args - Arguments after the executable path.
39
+ * @returns A completed result or the asynchronous marker.
40
+ */
41
+ runSync(args: readonly string[]): VirtualExecutableSyncResult;
42
+ }
43
+ /**
44
+ * Resolve a Worker platform executable by logical name.
45
+ * @param path - Bare name or executable path passed to `spawn`.
46
+ * @returns Its implementation, or undefined for the normal command table.
47
+ */
48
+ export declare function virtualExecutable(path: string): VirtualExecutable | undefined;
49
+ //# sourceMappingURL=virtual-executables.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shell builtins: the programs that read or change the shell's own state
3
+ * (directory, environment, exit status) rather than the filesystem.
4
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/programs/builtins
5
+ */
6
+ import type { ShellProgram } from '../types.ts';
7
+ /** The state builtins, keyed by the name a command line uses. */
8
+ export declare const BUILTIN_PROGRAMS: Readonly<Record<string, ShellProgram>>;
9
+ //# sourceMappingURL=builtins.d.ts.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * File and directory utilities of the command table, all of them over the
3
+ * shell's filesystem. Listings print one entry per line: nothing here is ever
4
+ * a terminal, so the column layout a real `ls` picks for a tty would only be
5
+ * noise in a tool result.
6
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/programs/files
7
+ */
8
+ import type { ShellProgram } from '../types.ts';
9
+ /** The file utilities, keyed by the name a command line uses. */
10
+ export declare const FILE_PROGRAMS: Readonly<Record<string, ShellProgram>>;
11
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The command table: every program name this shell can run. A browser worker
3
+ * spawns no processes, so this table IS the machine's `/bin` — a name that is
4
+ * not here reports `command not found`, exactly as a real shell would for a
5
+ * binary that is not installed.
6
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/programs
7
+ */
8
+ import type { ShellProgram } from '../types.ts';
9
+ /**
10
+ * The standard command table, built once and shared by every command line.
11
+ * @returns the program table, keyed by command name.
12
+ */
13
+ export declare function standardPrograms(): ReadonlyMap<string, ShellProgram>;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Argument splitting shared by the command table: short flags (bundled or
3
+ * separate), long flags, `--`, and the operands that follow.
4
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/programs/options
5
+ */
6
+ /** One parsed argv: which flags were given, and what is left to act on. */
7
+ export interface ParsedOptions {
8
+ /** Every short letter and long name seen, without their dashes. */
9
+ readonly flags: ReadonlySet<string>;
10
+ /** Values of flags that take one (`-n 5` and `--name=x` both land here). */
11
+ readonly values: ReadonlyMap<string, string>;
12
+ /** Everything that is not a flag, in order. */
13
+ readonly operands: readonly string[];
14
+ }
15
+ /**
16
+ * Split one program's arguments.
17
+ *
18
+ * A short letter listed in `valued` consumes the rest of its token (`-n5`) or
19
+ * the next argument (`-n 5`); every other letter is a plain flag, so `-rn`
20
+ * sets both `r` and `n`.
21
+ * @param argv - the program's argv, including its name at index 0.
22
+ * @param valued - short letters that take a value.
23
+ * @returns the flags, their values, and the operands.
24
+ */
25
+ export declare function parseOptions(argv: readonly string[], valued?: ReadonlySet<string>): ParsedOptions;
26
+ /**
27
+ * Read a numeric flag value.
28
+ * @param options - the parsed options.
29
+ * @param flag - the short letter to read.
30
+ * @param fallback - value to use when the flag is absent or unparsable.
31
+ * @returns the number the caller should use.
32
+ */
33
+ export declare function numberOption(options: ParsedOptions, flag: string, fallback: number): number;
34
+ /**
35
+ * Split text into lines for the line-oriented utilities.
36
+ * @param text - the text to split.
37
+ * @returns its lines, without the trailing empty line a final newline creates.
38
+ */
39
+ export declare function toLines(text: string): string[];
40
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Text utilities of the command table. Each one reads its operands as files
3
+ * and falls back to standard input, the way its POSIX counterpart does.
4
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/programs/text
5
+ */
6
+ import type { ShellProgram } from '../types.ts';
7
+ /** The text utilities, keyed by the name a command line uses. */
8
+ export declare const TEXT_PROGRAMS: Readonly<Record<string, ShellProgram>>;
9
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Types of the in-worker shell: the state one command line mutates, the byte
3
+ * face a program reads and writes, and the program signature the command table
4
+ * stores. A browser worker has no processes, so a "program" is a JavaScript
5
+ * function over the VFS and the state below is the whole machine.
6
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/shell/types
7
+ */
8
+ /**
9
+ * Mutable state of one shell instance. A subshell copies it; a group and the
10
+ * top level share it, which is what makes `cd` visible to later commands of
11
+ * the same line and invisible outside `( … )`.
12
+ */
13
+ export interface ShellState {
14
+ /** Absolute working directory every relative path resolves against. */
15
+ cwd: string;
16
+ /** Exported variables — the environment a program reads. */
17
+ environment: Record<string, string>;
18
+ /** Shell variables that were assigned but never exported. */
19
+ variables: Record<string, string>;
20
+ /** Exit status of the last completed command, read back as `$?`. */
21
+ lastStatus: number;
22
+ /** Set by `exit`; the interpreter stops the line and reports this status. */
23
+ exitRequested: number | undefined;
24
+ /**
25
+ * The caller's cancellation, for programs that would otherwise keep the
26
+ * whole line waiting after a kill. The interpreter checks it between
27
+ * commands; a program that waits on anything must check it too.
28
+ */
29
+ readonly signal: AbortSignal | undefined;
30
+ }
31
+ /**
32
+ * The byte face of one running program. Output is collected as text rather
33
+ * than streamed: every program is a JavaScript function that returns before
34
+ * the next one starts, so a pipeline is a string handed along, and nothing in
35
+ * this shell can observe a partially written stream.
36
+ */
37
+ export interface ShellIo {
38
+ /** Everything on standard input, already complete. */
39
+ readonly stdin: string;
40
+ /** Append to standard output. Declared as a value: redirections hand it around. */
41
+ readonly out: (text: string) => void;
42
+ /** Append to standard error. Declared as a value: redirections hand it around. */
43
+ readonly err: (text: string) => void;
44
+ }
45
+ /** One directory entry, as the listing, glob, and walk programs read it. */
46
+ export interface ShellDirent {
47
+ readonly name: string;
48
+ readonly directory: boolean;
49
+ }
50
+ /** What a program can learn about one path. */
51
+ export interface ShellStats {
52
+ readonly directory: boolean;
53
+ readonly size: number;
54
+ readonly mtimeMs: number;
55
+ }
56
+ /**
57
+ * The filesystem a shell run acts on.
58
+ *
59
+ * Asynchronous by construction: a command that runs in its own worker reaches
60
+ * the VFS by message, and the browser offers no way to block on that (a
61
+ * synchronous face would need `SharedArrayBuffer`, which requires
62
+ * cross-origin isolation this deployment cannot have). The in-host
63
+ * implementation answers immediately from the mounted VFS.
64
+ */
65
+ export interface ShellFileSystem {
66
+ /**
67
+ * Stat one path.
68
+ * @param path - absolute VFS path.
69
+ * @returns the entry's facts, or undefined when nothing is there.
70
+ */
71
+ stat(path: string): Promise<ShellStats | undefined>;
72
+ /**
73
+ * List one directory.
74
+ * @param path - absolute VFS path of the directory.
75
+ * @returns its entries, sorted by name.
76
+ * @throws a Node-shaped error when the path is absent or is not a directory.
77
+ */
78
+ list(path: string): Promise<ShellDirent[]>;
79
+ /**
80
+ * Read one file as UTF-8 text.
81
+ * @param path - absolute VFS path.
82
+ * @returns the file's contents.
83
+ * @throws a Node-shaped error when the path is absent or is a directory.
84
+ */
85
+ readText(path: string): Promise<string>;
86
+ /**
87
+ * Write text to one file.
88
+ * @param path - absolute VFS path; its parent must exist.
89
+ * @param text - the text to store.
90
+ * @param append - true to keep the existing contents and add after them.
91
+ */
92
+ writeText(path: string, text: string, append?: boolean): Promise<void>;
93
+ /**
94
+ * Create one directory.
95
+ * @param path - absolute VFS path.
96
+ * @param recursive - true to create missing parents and tolerate an existing directory.
97
+ */
98
+ mkdir(path: string, recursive: boolean): Promise<void>;
99
+ /**
100
+ * Remove one path.
101
+ * @param path - absolute VFS path.
102
+ * @param options - `recursive` to take a whole subtree, `force` to tolerate absence.
103
+ */
104
+ remove(path: string, options: {
105
+ recursive: boolean;
106
+ force: boolean;
107
+ }): Promise<void>;
108
+ /**
109
+ * Move one file or subtree.
110
+ * @param from - absolute source path.
111
+ * @param to - absolute destination path.
112
+ */
113
+ rename(from: string, to: string): Promise<void>;
114
+ }
115
+ /**
116
+ * One executable of the command table.
117
+ *
118
+ * A program reports its exit status like a POSIX process: 0 for success, and a
119
+ * nonzero status it also explains on {@link ShellIo.err}. Throwing is reserved
120
+ * for a defect in the program itself — the interpreter turns a throw into
121
+ * status 1 plus a diagnostic naming the program.
122
+ * @param argv - the program name at index 0, then its arguments, fully expanded.
123
+ * @param io - standard input contents and the output sinks.
124
+ * @param state - shell state; a program that changes it (`cd`, `export`) mutates in place.
125
+ * @param fs - the filesystem this run acts on.
126
+ * @returns the exit status.
127
+ */
128
+ export type ShellProgram = (argv: readonly string[], io: ShellIo, state: ShellState, fs: ShellFileSystem) => number | Promise<number>;
129
+ /** Outcome of one interpreted command line. */
130
+ export interface ShellRunOutcome {
131
+ /** Exit status of the last command the line ran. */
132
+ exitCode: number;
133
+ /** Everything written to standard output. */
134
+ stdout: string;
135
+ /** Everything written to standard error. */
136
+ stderr: string;
137
+ }
138
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Process-wide slot holding the mounted filesystem. Kept apart from any
3
+ * backend implementation: the `node:fs` proxy depends on the slot, not on
4
+ * which backend the worker entry mounted.
5
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/storage/active
6
+ */
7
+ import type { Vfs } from './types.ts';
8
+ /**
9
+ * Publish the filesystem the `node:fs` proxy reads.
10
+ * @param vfs - Filesystem mounted by the worker entry.
11
+ */
12
+ export declare function setActiveVfs(vfs: Vfs): void;
13
+ /**
14
+ * Read the mounted filesystem.
15
+ * @returns The active filesystem.
16
+ */
17
+ export declare function requireActiveVfs(): Vfs;
18
+ //# sourceMappingURL=active.d.ts.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The image byte envelope. The packer writes one gzip member holding the ustar
3
+ * archive, and the worker inflates it with the platform's own decompressor before
4
+ * the tar reader sees a byte — `storage/tar.ts` stays a pure ustar reader with no
5
+ * codec in it.
6
+ *
7
+ * Inflation runs on the fetch stream rather than on downloaded bytes: the
8
+ * decompressor consumes each chunk as it lands, so unpacking overlaps the
9
+ * download instead of following it, and the compressed copy never has to be held
10
+ * whole in memory beside the archive it produces.
11
+ *
12
+ * One format, no negotiation: a body that does not start a gzip member is refused
13
+ * by name, in the stream, before the decompressor sees it. Without that check a
14
+ * plain tar, a truncated download, or a proxy's HTML error page would reach
15
+ * `parseTar` and fail as a corrupt header field, which says nothing about what
16
+ * the deployment actually served.
17
+ * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/storage/image-gzip
18
+ */
19
+ /**
20
+ * Inflate a packed VFS image as it arrives.
21
+ * @param body - the image body, straight from `fetch` or wrapped around bytes.
22
+ * @param source - the image URL, or how the bytes arrived; named in a refusal.
23
+ * @returns the ustar archive the image carries.
24
+ * @throws When the body does not start a gzip member, or the member is corrupt.
25
+ */
26
+ export declare function inflateImageStream(body: ReadableStream<Uint8Array>, source: string): Promise<Uint8Array>;
27
+ /**
28
+ * Inflate a packed VFS image held in memory.
29
+ *
30
+ * The bytes become a body so both entries run the same stream: one decompression
31
+ * path, one refusal, whether the image came off the network or out of a caller's
32
+ * buffer.
33
+ * @param bytes - the image bytes.
34
+ * @param source - how the bytes arrived; named in a refusal.
35
+ * @returns the ustar archive the image carries.
36
+ * @throws When the bytes do not start a gzip member, or the member is corrupt.
37
+ */
38
+ export declare function inflateImage(bytes: Uint8Array, source: string): Promise<Uint8Array>;
39
+ //# sourceMappingURL=image-gzip.d.ts.map