char/avril

(wip) why'd you have to go and make things so complicaaaaated?

git clone https://git.t4t.associates/char/avril

Charlotte Somgenerate std typedefs from typescript impl38d7f6c

main
28.3 KiB699 linesraw
1import { SymbolFor } from "ext:core/primordials";
2import * as subprocess from "ext:process/main.js";
3import * as net from "ext:net/main.js";
4import * as file from "ext:file/main.js";
5import * as environment from "./env.js";
6import * as consoleInspection from "ext:console/inspect.js";
7import * as authority from "./pledge.js";
8import * as host from "./host.js";
9import * as http from "ext:http/main.js";
10import * as httpFile from "ext:http/file.js";
11import * as stdio from "ext:stdio/main.js";
12
13// Non-constructible class values still expose ordinary function reflection.
14type ClassStatics = Omit<Function, "prototype" | typeof Symbol.hasInstance>;
15
16export const avril: unique symbol = SymbolFor("runtime:avril") as typeof avril;
17
18export interface GrantRestriction<T> {
19  readonly allow?: readonly T[];
20  readonly deny?: readonly T[];
21}
22
23export interface Pledge {
24  readonly net?: false | GrantRestriction<string>;
25  readonly env?: false | GrantRestriction<string>;
26  readonly sys?: false | GrantRestriction<string>;
27  readonly read?: false | GrantRestriction<string | URL>;
28  readonly write?: false | GrantRestriction<string | URL>;
29  readonly jsExec?: false | GrantRestriction<string | URL>;
30  readonly run?: false | GrantRestriction<string | URL>;
31  readonly ffi?: false | GrantRestriction<string | URL>;
32}
33
34/** Irreversibly narrows authority; omitted categories are unchanged. */
35export const pledge: (restrictions: Pledge) => void = authority.pledge;
36
37/** Runtime-local environment; named operations require authority for that variable. */
38export const env: Readonly<{
39  get(name: string): string | undefined;
40  has(name: string): boolean;
41  set(name: string, value: string): void;
42  delete(name: string): void;
43  /** Returns an independent, null-prototype snapshot of permitted variables only. */
44  toObject(): Record<string, string>;
45}> = environment.env;
46
47/** This process. `pid` and `runtime` need no authority; `cwd()` requires read authority for the working directory, and the other methods each require sys authority for their own name ("hostname", "osRelease", "uptime", "loadavg"). Denied calls throw PermissionDenied. */
48export const process: Readonly<{
49  pid: number;
50  /** Frozen script arguments, excluding runtime options and entry modules; needs no authority. REPL and test sessions accept arguments after `--`. Workers inherit them. */
51  args: readonly string[];
52  cwd(): string;
53  hostname(): string;
54  osRelease(): string;
55  /** Seconds since the system booted. */
56  uptime(): number;
57  /** 1, 5, and 15 minute load averages; [0, 0, 0] on Windows. */
58  loadavg(): [number, number, number];
59}> = host.process;
60
61/** The avril build running this process; needs no authority. */
62export const runtime: Readonly<{
63  os: "linux" | "macos" | "windows";
64  arch: "x86_64" | "aarch64";
65  /** avril version. */
66  version: string;
67  /** V8 version. */
68  v8: string;
69}> = host.runtime;
70
71export interface InspectOptions {
72  /** Nesting levels to expand; `null` or `Infinity` expand as far as avril allows. Defaults to 3. */
73  depth?: number | null;
74  /** Wrap values in ANSI color escapes. */
75  colors?: boolean;
76}
77
78/**
79 * Formats a value the way `console.log` and the REPL show it, without invoking getters.
80 *
81 * An object customizes its format with a method keyed by
82 * `Symbol.for("runtime.avril.inspect")`, called as `method(inspect, options)`.
83 * A string result is used verbatim; any other result is inspected in its place.
84 * Inspecting the object again from inside its own method uses the default format.
85 */
86export const inspect: (value: unknown, options?: InspectOptions) => string = consoleInspection.inspect;
87
88export interface TcpAddr {
89  readonly transport: "tcp";
90  readonly hostname: string;
91  readonly port: number;
92}
93
94export interface UnixAddr {
95  readonly transport: "unix";
96  readonly path: string | null;
97}
98
99export interface UdpAddr {
100  readonly transport: "udp";
101  readonly hostname: string;
102  readonly port: number;
103}
104export type StreamAddr = TcpAddr | UnixAddr;
105export type Addr = StreamAddr | UdpAddr;
106
107export interface ServeInfo<A extends StreamAddr = StreamAddr> {
108  readonly remoteAddr: A;
109}
110
111export type ServeHandler<A extends StreamAddr = StreamAddr> = (
112  request: Request,
113  info: ServeInfo<A>,
114) => Response | Promise<Response>;
115
116export interface ServeOptions {
117  path?: never;
118  /** Defaults to 127.0.0.1. */
119  hostname?: string;
120  /** Defaults to 8000; 0 selects an available port. */
121  port?: number;
122  /** Aborting stops the listener and closes active connections immediately. */
123  signal?: AbortSignal;
124  onListen?: (addr: TcpAddr) => void;
125  /** Handler errors default to a 500 response. */
126  onError?: (error: unknown) => Response | Promise<Response>;
127}
128
129export interface UnixServeOptions extends Omit<ServeOptions, "hostname" | "port" | "path" | "onListen"> {
130  path: string;
131  hostname?: never;
132  port?: never;
133  onListen?: (addr: UnixAddr) => void;
134}
135
136export interface ServeModule {
137  fetch: ServeHandler;
138}
139
140export interface HttpServer<A extends StreamAddr = StreamAddr> {
141  readonly addr: A;
142  readonly finished: Promise<void>;
143  /** Stops accepting connections and waits for active responses. */
144  shutdown(): Promise<void>;
145}
146
147/** Serves HTTP/1.1; TCP requires net authority, Unix sockets require write authority. */
148export const serve: {
149  (handler: ServeHandler<TcpAddr>): HttpServer<TcpAddr>;
150  (options: ServeOptions, handler: ServeHandler<TcpAddr>): HttpServer<TcpAddr>;
151  (options: UnixServeOptions, handler: ServeHandler<UnixAddr>): HttpServer<UnixAddr>;
152} = http.serve;
153
154export interface ServeFileOptions {
155  /** Additional headers; Content-Type and ETag override the defaults. */
156  headers?: HeadersInit;
157  /** Transfers ownership of a supplied FileHandle. Defaults to true; ignored for paths. */
158  consume?: boolean;
159}
160
161/** Streams a regular file with conditional and single-range support; requires read authority. */
162export const serveFile: (
163  request: Request,
164  source: string | URL | FileHandle,
165  options?: ServeFileOptions,
166) => Promise<Response> = httpFile.serveFile;
167
168export const upgradeWebSocket: (
169  request: Request,
170  options?: { protocol?: string },
171) => { socket: WebSocket; response: Response } = http.upgradeWebSocket;
172
173export interface TcpListenOptions {
174  transport?: "tcp";
175  hostname?: string;
176  port: number;
177}
178export interface TcpConnectOptions extends TcpListenOptions {
179  signal?: AbortSignal;
180}
181export interface UnixListenOptions {
182  transport: "unix";
183  path: string;
184  hostname?: never;
185  port?: never;
186}
187export interface UnixConnectOptions extends UnixListenOptions {
188  signal?: AbortSignal;
189}
190export interface Conn<A extends StreamAddr = TcpAddr> {
191  readonly localAddr: A;
192  readonly remoteAddr: A;
193  read(buffer: Uint8Array): Promise<number | null>;
194  write(buffer: Uint8Array): Promise<number>;
195  /** Writes every view in order before resolving; unlike write, success means the whole vector was written. */
196  writev(buffers: readonly Uint8Array[]): Promise<number>;
197  closeWrite(): Promise<void>;
198  close(): void;
199  [Symbol.dispose](): void;
200  readonly readable: ReadableStream<Uint8Array>;
201  readonly writable: WritableStream<Uint8Array>;
202}
203
204export const Conn: ClassStatics & {
205  readonly prototype: Conn<StreamAddr>;
206  [Symbol.hasInstance](value: unknown): value is Conn<StreamAddr>;
207} = net.Conn;
208export interface Listener<A extends StreamAddr = TcpAddr> extends AsyncIterable<Conn<A>> {
209  readonly addr: A;
210  accept(): Promise<Conn<A>>;
211  close(): void;
212  [Symbol.dispose](): void;
213  [Symbol.asyncIterator](): AsyncIterator<Conn<A>>;
214}
215
216export const Listener: ClassStatics & {
217  readonly prototype: Listener<StreamAddr>;
218  [Symbol.hasInstance](value: unknown): value is Listener<StreamAddr>;
219} = net.Listener;
220export const connect: {
221  (options: TcpConnectOptions): Promise<Conn<TcpAddr>>;
222  (options: UnixConnectOptions): Promise<Conn<UnixAddr>>;
223} = net.connect;
224export const listen: {
225  (options: TcpListenOptions): Listener<TcpAddr>;
226  (options: UnixListenOptions): Listener<UnixAddr>;
227} = net.listen;
228
229export interface UdpListenOptions {
230  transport?: "udp";
231  hostname?: string;
232  port: number;
233}
234export interface UdpSendOptions {
235  transport?: "udp";
236  hostname?: string;
237  port: number;
238}
239export interface DatagramConn extends AsyncIterable<[Uint8Array, UdpAddr]> {
240  readonly addr: UdpAddr;
241  receive(buffer?: Uint8Array): Promise<[Uint8Array, UdpAddr]>;
242  send(buffer: Uint8Array, target: UdpSendOptions): Promise<number>;
243  setBroadcast(enabled?: boolean): void;
244  close(): void;
245  [Symbol.dispose](): void;
246  [Symbol.asyncIterator](): AsyncIterator<[Uint8Array, UdpAddr]>;
247}
248
249export const DatagramConn: ClassStatics & {
250  readonly prototype: DatagramConn;
251  [Symbol.hasInstance](value: unknown): value is DatagramConn;
252} = net.DatagramConn;
253export const listenDatagram: (options: UdpListenOptions) => DatagramConn = net.listenDatagram;
254
255export interface OpenOptions {
256  read?: boolean;
257  write?: boolean;
258  append?: boolean;
259  truncate?: boolean;
260  create?: boolean;
261  createNew?: boolean;
262  mode?: number;
263}
264
265export interface FileInfo {
266  isFile: boolean;
267  isDirectory: boolean;
268  isSymlink: boolean;
269  size: number;
270  mtime: Date | null;
271  atime: Date | null;
272  birthtime: Date | null;
273  mode: number | null;
274  uid: number | null;
275  gid: number | null;
276}
277
278export const SeekMode: Readonly<{ Start: 0; Current: 1; End: 2 }> = file.SeekMode;
279export interface FileHandle {
280  read(buffer: Uint8Array): Promise<number | null>;
281  write(buffer: Uint8Array): Promise<number>;
282  /** Writes every view in order before resolving; unlike write, success means the whole vector was written. */
283  writev(buffers: readonly Uint8Array[]): Promise<number>;
284  seek(offset: number, whence: 0 | 1 | 2): Promise<number>;
285  stat(): Promise<FileInfo>;
286  truncate(length?: number): Promise<void>;
287  sync(): Promise<void>;
288  syncData(): Promise<void>;
289  fchmod(mode: number): Promise<void>;
290  fchown(uid: number | null, gid: number | null): Promise<void>;
291  /** Times are seconds since the Unix epoch, like Deno and Node; Dates are accepted. */
292  futime(atime: number | Date, mtime: number | Date): Promise<void>;
293  /** Acquires an advisory lock, exclusive by default (unlike Deno's shared default). Waiting releases the handle queue, so a lock does not serialize with reads and writes. */
294  flock(exclusive?: boolean): Promise<void>;
295  funlock(): Promise<void>;
296  /** Synchronous operations share the native queue with async calls; they do not run JS callbacks while waiting. */
297  readSync(buffer: Uint8Array): number | null;
298  writeSync(buffer: Uint8Array): number;
299  /** Writes every view in order before returning; unlike writeSync, a normal return means the whole vector was written. */
300  writevSync(buffers: readonly Uint8Array[]): number;
301  seekSync(offset: number, whence: 0 | 1 | 2): number;
302  statSync(): FileInfo;
303  truncateSync(length?: number): void;
304  syncSync(): void;
305  syncDataSync(): void;
306  fchmodSync(mode: number): void;
307  fchownSync(uid: number | null, gid: number | null): void;
308  futimeSync(atime: number | Date, mtime: number | Date): void;
309  /** Like flock(), waiting releases the handle queue, but blocks this isolate. */
310  flockSync(exclusive?: boolean): void;
311  funlockSync(): void;
312  close(): void;
313  [Symbol.dispose](): void;
314  readonly readable: ReadableStream<Uint8Array>;
315  readonly writable: WritableStream<Uint8Array>;
316}
317
318export const FileHandle: ClassStatics & {
319  readonly prototype: FileHandle;
320  [Symbol.hasInstance](value: unknown): value is FileHandle;
321} = file.FileHandle;
322export const open: (
323  path: string | URL,
324  options?: OpenOptions,
325) => Promise<FileHandle> = file.open;
326export const create: (path: string | URL) => Promise<FileHandle> = file.create;
327export const stat: (path: string | URL) => Promise<FileInfo> = file.stat;
328export const lstat: (path: string | URL) => Promise<FileInfo> = file.lstat;
329export interface DirEntry {
330  name: string;
331  isFile: boolean;
332  isDirectory: boolean;
333  isSymlink: boolean;
334}
335export const readDir: (path: string | URL) => AsyncIterable<DirEntry> = file.readDir;
336export type FsEventKind =
337  | "create"
338  | "modify"
339  | "remove"
340  | "rename"
341  | "rescan";
342export interface FsEvent {
343  readonly kind: FsEventKind;
344  /** Absolute paths under the canonicalized watched root. A rename has the source first and destination second; a rescan names each root whose contents should be read again. Events may be coalesced, and access events are not reported. */
345  readonly paths: readonly string[];
346}
347export interface WatchOptions {
348  /** Watch subdirectories, including ones created later; defaults to true. Ignored for file roots. */
349  recursive?: boolean;
350  /** Aborting closes the watcher and ends iteration without throwing the abort reason. */
351  signal?: AbortSignal;
352}
353export interface FsWatcher extends AsyncIterable<FsEvent> {
354  close(): void;
355  /** Keeps the process alive while the watcher is open, including between iterations; this is the default. */
356  ref(): void;
357  /** Allows the process to exit even while the watcher is open. */
358  unref(): void;
359  [Symbol.dispose](): void;
360  [Symbol.asyncIterator](): AsyncIterator<FsEvent>;
361}
362
363export const FsWatcher: ClassStatics & {
364  readonly prototype: FsWatcher;
365  [Symbol.hasInstance](value: unknown): value is FsWatcher;
366} = file.FsWatcher;
367/** Watches existing files or directories; requires read authority for each root and, for recursive directories, its whole tree. Events are rechecked against live read authority when delivered. A file root stays attached to its path across replacement and recreation; removing or renaming away a directory root ends its watch once every root is gone. */
368export const watchFs: (
369  paths: string | URL | Iterable<string | URL>,
370  options?: WatchOptions,
371) => FsWatcher = file.watchFs;
372export const mkdir: (
373  path: string | URL,
374  options?: { mode?: number },
375) => Promise<void> = file.mkdir;
376export const remove: (
377  path: string | URL,
378  options?: { recursive?: boolean },
379) => Promise<void> = file.remove;
380/** Requires directory-shaped authority over the source (read/write) and destination (write). Scoped directory renames containing symlinks are not yet implemented. */
381export const rename: (
382  source: string | URL,
383  destination: string | URL,
384) => Promise<void> = file.rename;
385export const copyFile: (
386  source: string | URL,
387  destination: string | URL,
388) => Promise<void> = file.copyFile;
389/** Stores target text unchanged; requires write at the link and read/write tree authority over its target. Creation on Windows is not yet implemented. */
390export const symlink: (
391  target: string | URL,
392  linkPath: string | URL,
393  options?: { type?: "file" | "dir" },
394) => Promise<void> = file.symlink;
395/** Reads the link's stored text, not its referent. */
396export const readLink: (path: string | URL) => Promise<string> = file.readLink;
397export const realPath: (path: string | URL) => Promise<string> = file.realPath;
398/** Changes the file mode bits. Follows links. */
399export const chmod: (path: string | URL, mode: number) => Promise<void> = file.chmod;
400/** Null keeps that id; 4294967295 is rejected. Follows links. */
401export const chown: (
402  path: string | URL,
403  uid: number | null,
404  gid: number | null,
405) => Promise<void> = file.chown;
406/** Like chown but acts on the link itself. */
407export const lchown: (
408  path: string | URL,
409  uid: number | null,
410  gid: number | null,
411) => Promise<void> = file.lchown;
412/** Times are seconds since the Unix epoch, like Deno and Node; Dates are accepted. Follows links. */
413export const utime: (
414  path: string | URL,
415  atime: number | Date,
416  mtime: number | Date,
417) => Promise<void> = file.utime;
418/** Like utime but acts on the link itself; a trailing slash follows instead. */
419export const lutime: (
420  path: string | URL,
421  atime: number | Date,
422  mtime: number | Date,
423) => Promise<void> = file.lutime;
424/** Requires read and write authority over the source and write over the destination; symlink sources are refused. */
425export const link: (
426  oldpath: string | URL,
427  newpath: string | URL,
428) => Promise<void> = file.link;
429/** Sets the file size, zero-filling growth. Follows links. */
430export const truncate: (path: string | URL, length?: number) => Promise<void> = file.truncate;
431export const errors: Readonly<
432  Record<
433    | "NotFound"
434    | "PermissionDenied"
435    | "AlreadyExists"
436    | "NotEmpty"
437    | "CrossDevice"
438    | "NotADirectory"
439    | "IsADirectory"
440    | "InvalidInput"
441    | "BadResource"
442    | "Busy"
443    | "BrokenPipe"
444    | "NotSupported"
445    | "IoError",
446    new (message?: string) => Error
447  >
448> = file.errors;
449
450export type ProcessReason =
451  | "abort"
452  | "timeout"
453  | "output-limit"
454  | "terminated"
455  | "dispose"
456  | "owner"
457  | "io-error"
458  | "drain-timeout";
459export interface ProcessStatus {
460  readonly code: number | null;
461  readonly signal: string | null;
462  readonly success: boolean;
463  readonly reason: ProcessReason | null;
464  readonly error: string | null;
465}
466export interface ProcessOutput<T = Uint8Array> extends ProcessStatus {
467  readonly stdout: T | null;
468  readonly stderr: T | null;
469}
470/** File redirections resolve against the child working directory. The file mode is output-only; stdin files accept no mode. */
471export type ProcessStdio = "piped" | "inherit" | "null" | {
472  file: string | URL;
473  mode?: "truncate" | "append" | "create-new";
474} | { handle: FileHandle };
475export type ExtraProcessStdio = {
476  pipe: "parent-to-child" | "child-to-parent";
477} | {
478  file: string | URL;
479  mode?: "truncate" | "append" | "create-new";
480  direction: "parent-to-child" | "child-to-parent";
481} | { handle: FileHandle; direction: "parent-to-child" | "child-to-parent" };
482export interface ProcessOptions {
483  args?: Iterable<string>;
484  cwd?: string | URL;
485  /** Bare names search only the effective child environment's PATH. False uses a pathname relative to child cwd. */
486  searchPath?: boolean;
487  clearEnv?: boolean;
488  env?: Record<string, string>;
489  stdin?: ProcessStdio;
490  stdout?: ProcessStdio;
491  stderr?: ProcessStdio | "stdout";
492  input?: string | Uint8Array | ReadableStream<Uint8Array>;
493  encoding?: string;
494  /** False returns nonzero exits instead of throwing; timeout, abort, output-limit, and IO failures still throw. */
495  check?: boolean;
496  signal?: AbortSignal;
497  timeoutMs?: number;
498  /** Combined limit on output kept in memory for a result: stdout and stderr when collected, and stderr alone while lines() streams stdout. Defaults to 128 MiB; exceeding it terminates the child. */
499  maxCollectedBytes?: number;
500  /** Maximum unread native queue per stream; defaults to 1 MiB. For spawn's streams, overflow terminates the child; there is no backpressure. run() and runSync() always drain their output, so they block the child instead. */
501  maxBufferedBytes?: number;
502  termination?: {
503    /** Group termination covers the child's process group. With a terminal attached, children that inherit standard streams instead join the parent's group so terminal IO (including /dev/tty) keeps working; kill() then targets only the child. Unowned SIGINT/SIGTERM stop children gracefully before exiting; a repeat signal shortens that wait. Serve owns its shutdown signals and drains in-flight subprocess work. REPL interruption stops only the session's blocking runSync. On Windows the group is the child's job object, and SIGTERM, SIGINT, SIGQUIT, and SIGKILL all terminate at once with exit code 1 and no signal, so graceMs has no effect; other signals reject with NotSupported. Console Ctrl-C also reaches Windows children directly, as a shared terminal's interrupt does on Unix. */
504    scope?: "group" | "child";
505    signal?: string;
506    graceMs?: number;
507  };
508  drainTimeoutMs?: number;
509}
510export interface SpawnOptions extends ProcessOptions {
511  /** On Windows, descriptors up to 254 reach children through the C runtime's inherited descriptor table, so only CRT-based programs see them. */
512  extraStdio?: Record<number, ExtraProcessStdio>;
513  /** Not yet supported on Windows. */
514  terminal?: { columns?: number; rows?: number };
515}
516export interface ProcessTerminal {
517  readonly readable: ReadableStream<Uint8Array>;
518  readonly writable: WritableStream<Uint8Array>;
519  resize(columns: number, rows: number): void;
520}
521/** One native invocation, owned by this isolate. Native execution is not sandboxed. On Linux, shebang scripts observe /dev/fd/N as their path while the executable stays pinned. */
522export interface ChildProcess<T = Uint8Array> extends AsyncDisposable {
523  readonly pid: number;
524  /** Null when automatic input owns stdin. */
525  readonly stdin: WritableStream<Uint8Array> | null;
526  readonly stdout: ReadableStream<Uint8Array> | null;
527  readonly stderr: ReadableStream<Uint8Array> | null;
528  readonly stdio: Readonly<
529    Record<number, ReadableStream<Uint8Array> | WritableStream<Uint8Array>>
530  >;
531  readonly terminal: ProcessTerminal | null;
532  readonly status: Promise<ProcessStatus>;
533  readonly completed: Promise<ProcessStatus>;
534  /** Collects once, never respawns; rejects previously read or locked output. */
535  output(): Promise<ProcessOutput<T>>;
536  /** Sends one signal to the termination scope (the whole process group by default, or just the child when it shares the parent's group). */
537  kill(signal?: string): boolean;
538  terminate(): Promise<ProcessStatus>;
539  ref(): void;
540  unref(): void;
541  [Symbol.asyncDispose](): Promise<void>;
542}
543
544export const ChildProcess: ClassStatics & {
545  readonly prototype: ChildProcess<Uint8Array | string>;
546  [Symbol.hasInstance](value: unknown): value is ChildProcess<Uint8Array | string>;
547} = subprocess.ChildProcess;
548export interface ProcessError extends Error {
549  readonly result: ProcessOutput<Uint8Array | string> | null;
550}
551
552export const ProcessError: Omit<ErrorConstructor, "prototype"> & {
553  readonly prototype: ProcessError;
554  new (
555    message: string,
556    result?: ProcessOutput<Uint8Array | string> | null,
557    cause?: unknown,
558  ): ProcessError;
559  [Symbol.hasInstance](value: unknown): value is ProcessError;
560} = subprocess.ProcessError;
561export interface OutputLimitError extends ProcessError {
562}
563
564export const OutputLimitError: Omit<ErrorConstructor, "prototype"> & {
565  readonly prototype: OutputLimitError;
566  new (result: ProcessOutput<Uint8Array | string>): OutputLimitError;
567  [Symbol.hasInstance](value: unknown): value is OutputLimitError;
568} = subprocess.OutputLimitError;
569export interface ProcessTimeoutError extends ProcessError {
570}
571
572export const ProcessTimeoutError: Omit<ErrorConstructor, "prototype"> & {
573  readonly prototype: ProcessTimeoutError;
574  new (result: ProcessOutput<Uint8Array | string>): ProcessTimeoutError;
575  [Symbol.hasInstance](value: unknown): value is ProcessTimeoutError;
576} = subprocess.ProcessTimeoutError;
577export interface ProcessAbortError extends ProcessError {
578}
579
580export const ProcessAbortError: Omit<ErrorConstructor, "prototype"> & {
581  readonly prototype: ProcessAbortError;
582  new (
583    result: ProcessOutput<Uint8Array | string> | null,
584    cause?: unknown,
585  ): ProcessAbortError;
586  [Symbol.hasInstance](value: unknown): value is ProcessAbortError;
587} = subprocess.ProcessAbortError;
588/** Authorizes native execution through run capabilities, independently of read and jsExec; the child is not sandboxed by avril's capabilities. Supported on Linux, macOS, and Windows 10 1607 or later; other platforms reject launch with NotSupported. On Linux, when close_range is unavailable, descriptor isolation requires /proc/self/fd. Linux pins the executable through exec; macOS launches the authorized path, and Windows holds it open against replacement until launch. Abruptly killed owners take their direct children with them on Linux and the child's job on Windows; on macOS only orderly exits clean up. Windows rejects batch files (run cmd.exe explicitly), and names without a .com or .exe extension also try both. Grants and denials name executable entries, not programs: aliases and hard links to the same binary need their own entries. On case-insensitive filesystems they match an entry by its stored spelling. Relative grants resolve against the grant-time working directory, not PATH. Unref'd children are terminated when their owner exits; only direct children are pinned to the owner's lifetime, so group grandchildren rely on group termination. Unix supervision preserves inherited ignored signal dispositions. No implicit shell. */
589export const run: {
590  (
591    command: string | URL,
592    options?: ProcessOptions & { encoding?: undefined },
593  ): ProcessPromise;
594  (
595    command: string | URL,
596    options: ProcessOptions & { encoding: string },
597  ): ProcessPromise<string>;
598  (
599    command: string | URL,
600    args: Iterable<string> | undefined,
601    options?: ProcessOptions & { args?: undefined; encoding?: undefined },
602  ): ProcessPromise;
603  (
604    command: string | URL,
605    args: Iterable<string> | undefined,
606    options: ProcessOptions & { args?: undefined; encoding: string },
607  ): ProcessPromise<string>;
608} = subprocess.run;
609/** The run() result, with shortcuts to its stdout. Each shortcut fails like the run itself; stdout decodes with the encoding option, or UTF-8. */
610export interface ProcessPromise<T = Uint8Array>
611  extends Promise<ProcessOutput<T>> {
612  bytes(): Promise<Uint8Array>;
613  text(): Promise<string>;
614  json(): Promise<unknown>;
615  /** Stdout lines without their \n or \r\n. Called in the same turn as run(), it streams as the child writes, and the run's failures surface after the last line; a stopped run (timeout, abort, termination) ends iteration without the lines still queued, and ending iteration early terminates the child, so the run rejects as terminated. Past maxBufferedBytes unread, the child blocks until the loop catches up, so iterate rather than only awaiting the run. Streamed stdout is not collected and does not count toward maxCollectedBytes. Called later, it splits the collected output. */
616  lines(): AsyncIterableIterator<string>;
617}
618export type RunSyncOptions = Omit<ProcessOptions, "input" | "signal"> & {
619  input?: string | Uint8Array;
620};
621export const runSync: {
622  (
623    command: string | URL,
624    options?: RunSyncOptions & { encoding?: undefined },
625  ): ProcessOutput;
626  (
627    command: string | URL,
628    options: RunSyncOptions & { encoding: string },
629  ): ProcessOutput<string>;
630  (
631    command: string | URL,
632    args: Iterable<string> | undefined,
633    options?: RunSyncOptions & { args?: undefined; encoding?: undefined },
634  ): ProcessOutput;
635  (
636    command: string | URL,
637    args: Iterable<string> | undefined,
638    options: RunSyncOptions & { args?: undefined; encoding: string },
639  ): ProcessOutput<string>;
640} = subprocess.runSync;
641export const spawn: {
642  (
643    command: string | URL,
644    options?: SpawnOptions & { encoding?: undefined },
645  ): ChildProcess;
646  (
647    command: string | URL,
648    options: SpawnOptions & { encoding: string },
649  ): ChildProcess<string>;
650  (
651    command: string | URL,
652    args: Iterable<string> | undefined,
653    options?: SpawnOptions & { args?: undefined; encoding?: undefined },
654  ): ChildProcess;
655  (
656    command: string | URL,
657    args: Iterable<string> | undefined,
658    options: SpawnOptions & { args?: undefined; encoding: string },
659  ): ChildProcess<string>;
660} = subprocess.spawn;
661
662/**
663 * Listens for a process signal, Deno-style. Supported on Linux and
664 * macOS for SIGINT, SIGTERM, SIGHUP, SIGUSR1, SIGUSR2, and SIGWINCH;
665 * other platforms and other signals throw NotSupported, while
666 * unknown names and the uncatchable SIGKILL/SIGSTOP throw
667 * InvalidInput. Listening needs no pledge.
668 *
669 * Signals are process-wide: each delivery reaches every live isolate
670 * that binds it (entry, REPL, workers), with one isolate's listeners
671 * firing in binding order. But only the entry isolate (and the REPL's
672 * main isolate) suppress the default death: worker listeners observe
673 * every delivery but never count, so with no entry listener a lethal
674 * delivery still kills the process and worker delivery is best-effort.
675 * A worker that must finish cleanup cannot rely on its own listener;
676 * the entry module must listen instead and coordinate, the same shape
677 * as serve's shutdown: entry listens, notifies workers, waits for
678 * their acks, then exits. Once the last entry listener goes away the
679 * prior fate returns. An active listener keeps the event loop alive,
680 * like a referenced handle.
681 *
682 * Reserved owners still run alongside listeners: serve owns SIGINT and
683 * SIGTERM for shutdown, and the REPL owns SIGINT for eval interrupt, so
684 * listening to those observes the shutdown or interrupt rather than
685 * replacing it.
686 */
687export const addSignalListener: (
688  signal: string,
689  listener: () => void,
690) => void = subprocess.addSignalListener;
691/** Stops a listener added with addSignalListener; unknown pairs are a no-op. */
692export const removeSignalListener: (
693  signal: string,
694  listener: () => void,
695) => void = subprocess.removeSignalListener;
696
697export const stdin: ReadableStream<Uint8Array> = stdio.stdin;
698export const stdout: WritableStream<Uint8Array> = stdio.stdout;
699export const stderr: WritableStream<Uint8Array> = stdio.stderr;