import { IOResult } from '../../../io/types.ts'; import type { SessionView } from '../../../ops/types.ts'; import type { PolicyDenied } from '../../../policy/errors.ts'; import type { ArithError } from '../../../shell/errors.ts'; import { PathSpec } from '../../../types.ts'; import type { Namespace } from '../../mount/namespace/namespace.ts'; import type { Result } from './types.ts'; interface ResultInit { out?: Uint8Array | null; exitCode?: number; stderr?: string; io?: IOResult; } /** * Build the (stream, IOResult, ExecutionNode) triple builtins return. * * @param cmd - command name recorded on the ExecutionNode. * @param init - `out` stdout payload; `exitCode` for both results; `stderr` * error text encoded onto both; `io` a prebuilt IOResult to reuse (e.g. * carrying writes), whose exitCode/stderr are overwritten. */ export declare function result(cmd: string, init?: ResultInit): Result; export declare function ok(cmd: string, out?: Uint8Array | null): Result; export declare function fail(cmd: string, message: string, exitCode?: number): Result; /** * Close an operand loop: exit 1 with joined stderr when any operand failed, * exit 0 otherwise. * * @param cmd - command name. * @param errors - per-operand error messages collected so far. * @param io - prebuilt IOResult to reuse (e.g. carrying writes). */ export declare function finish(cmd: string, errors: string[], io?: IOResult): Result; /** * A non-path operand's text (a mode or owner spec the classifier may have * wrapped as a path). * * @param arg - a classified command part. */ export declare function operandText(arg: string | PathSpec): string; /** * A path operand as an absolute virtual path. * * @param arg - a classified command part. * @param cwd - session working directory for relative operands. */ export declare function absPath(arg: string | PathSpec, cwd: string): string; /** * Split leading single-letter flags, permissively. * * A token containing any unknown letter is kept as an operand instead of * erroring (`ln`/`readlink` behavior). * * @param args - args after the command name. * @param known - accepted single-letter flags. * @returns [flags, operands]. */ export declare function splitFlags(args: (string | PathSpec)[], known: string): [Set, (string | PathSpec)[]]; export interface SplitValueFlags { flags: Set; values: Map; operands: (string | PathSpec)[]; bad: string | null; } /** * Split leading flags where some take a value (`-t STAMP`), strictly: an * unknown letter is reported instead of tolerated. * * @param args - args after the command name. * @param boolean - single-letter flags with no value. * @param valued - single-letter flags that consume the next arg. */ export declare function splitValueFlags(args: readonly (string | PathSpec)[], boolean: string, valued: string): SplitValueFlags; /** * Coerce operands to PathSpec and expand glob patterns per mount. * * A pattern spec only exists for a mounted word (classification gates it), so * the lookup propagates on a miss; a backend with no glob keeps the literal * spec. * * @param namespace - addressing authority (mount lookup). * @param operands - positional operands. */ export declare function expandOperands(namespace: Namespace, operands: readonly (string | PathSpec)[]): Promise; /** * The gated session view this builtin writes through. * * Every session write goes through the workspace's gated view, which is * what makes `preSession` rules enforceable; this used to fall back to * an ungated view over the same session, so a caller that forgot to * thread one silently wrote past every policy. A write reached without * a view is a wiring bug, not a mode, so it throws. */ export declare function requireView(state: SessionView | null): SessionView; /** Render a policy denial in the builtin's own voice. */ export declare function refusal(cmd: string, err: PolicyDenied): Result; /** Render the shell's own readonly refusal, checked before the door. */ export declare function readOnlyError(cmd: string, namespace: Namespace, path: PathSpec): string; export declare function readonlyRefusal(cmd: string, name: string): Result; /** * Render the `-i` coercion's arithmetic error as bash does. * * GNU voices it as the evaluator's own line, prefixed by the builtin and * the offending text (`bash: read: 1+: syntax error: operand expected`), * and fails the builtin with 1 while the variable keeps its old value, * which is what the door's copy-then-store already guarantees. A plain * assignment (`n=1+`) is fatal instead and is voiced by the executor * without a builtin name. */ export declare function arithRefusal(cmd: string, err: ArithError): Result; /** Whether the word is a shell identifier. */ export declare function isValidName(name: string): boolean; /** * Whether the word is an optionally signed run of digits, which is what * `shift`, `return` and `exit` accept as their argument. */ export declare function isCountWord(word: string): boolean; export {}; //# sourceMappingURL=shared.d.ts.map