UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

61 lines • 4.1 kB
import type { RedirectResult } from '../../../../context/session_context.ts'; import type { ByteSource } from '../../../../io/types.ts'; import { IOResult } from '../../../../io/types.ts'; import type { DispatchFn } from '../../../../runtime/types.ts'; import { type Redirect, type TSNodeLike } from '../../../../shell/types.ts'; import type { ExecuteFn } from '../../../expand/types.ts'; import type { MountRegistry } from '../../../mount/registry.ts'; import type { SessionState } from '../../../session/session.ts'; import { type Written } from '../../statement.ts'; import type { BuiltinCall } from '../types.ts'; /** * The `exec` builtin without redirects. Bare `exec` is a no-op that * succeeds. `exec CMD ...` runs CMD as a program and ends the shell with its * status, as bash replaces the shell with it: the rest of the scope (the * line at top level, a subshell, a substitution, a nested shell) does not * run, and the replaced shell's actions go with it, EXIT included. A head no * program answers to (a builtin of the shell's own, a function, nothing) is * `exec: NAME: not found`, which ends the shell with 127 and runs its EXIT * action, as bash's does. `-c` runs CMD with an empty environment; `-a` and * `-l` name an argv[0] that mirage's programs do not read, and are refused. * The redirect-only form (`exec > file`) never reaches here: it is a * redirected statement, handled where redirects are applied. Mirrors Python. */ export declare function handleExecCommand(args: string[], session: SessionState, executeFn?: ExecuteFn | null, registry?: MountRegistry | null, stdin?: ByteSource | null): Promise<RedirectResult>; /** * Point the shell's own streams at files for the rest of the shell. `exec * > file` diverts later stdout, `2> file` stderr, `< file` stdin, `>>` * appends; `2>&1`/`>&2` copy one target onto the other; `>&-` closes. * The output file is opened now, as bash opens it at exec time. Numbered * descriptors use the same bindings and share open descriptions when duplicated, * and a copy of a terminal stream stays that stream when the shell later * rebinds its own (`exec 3>&1; exec >f`). */ export declare function installExecRedirects(dispatch: DispatchFn, session: SessionState, redirects: Redirect[], stdin?: ByteSource | null, expand?: (redirect: Redirect) => Promise<Redirect>): Promise<RedirectResult>; /** * Send one statement's output where the shell's `exec` bindings point. * Called after each statement of a shell's own loop; with no `exec` * redirect in force (or no dispatcher) the output passes through. A * stream bound to a file is appended to it (the first write to each * target having truncated it at `exec` time), one bound to the other * terminal stream crosses over (`exec 2>&1` puts stderr on stdout), a * closed one is dropped, and one bound to stdin fails with bash's `write * error: Bad file descriptor`, which is reported on stderr through * stderr's own binding and makes the statement's status 1, which `$?` * shows. An unwritable stderr fails only a statement that sent its own * stdout there (`>&2`); a lost diagnostic leaves the status the command * earned. A closed pipe is SIGPIPE for the writer: a program or subshell ends * with 141, the shell's own write ends the shell. `command` is the statement's recorded * line; its first word names the writer in a write error. `written` is the * statement's output in order; what went to the terminal through a copy * keeps its place. Returns what is left for the terminal, in the order it * was written. Mirrors Python's divert_statement. */ export declare function divertStatement(dispatch: DispatchFn | undefined, session: SessionState, written: readonly Written[], io: IOResult, statement: TSNodeLike, command: string): Promise<readonly Written[]>; /** * The `exec` arm. The redirect-only form is intercepted where redirects * are applied; a bare `exec` here has none, and `exec cmd` runs the * command and ends the shell. */ export declare function execBuiltin(call: BuiltinCall): Promise<RedirectResult>; //# sourceMappingURL=exec.d.ts.map