@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
48 lines • 2.89 kB
TypeScript
import type { RedirectResult } from '../../../../context/session_context.ts';
import type { DispatchFn } from '../../../../runtime/types.ts';
import type { SessionState } from '../../../session/session.ts';
/**
* A diagnostic from a shell that never got as far as running.
*
* `prefix` and `command` come apart because bash reports itself by
* `argv[0]`, which for a script operand is the operand: the recorded
* command still has to be the builtin that ran, not a file path.
*/
export declare function scriptError(prefix: string, message: string, code: number, command?: string): RedirectResult;
/**
* Read a script file through the op dispatcher.
*
* Every way of running a script off a mount comes through here, so a backend
* quirk is answered once rather than per caller. The one answered today is a
* directory, which only a real filesystem reports as EISDIR on read: a keyed
* backend has no directory object to open and answers ENOENT, ssh's raw error
* carries no errno, and WebDAV serves the collection's HTML listing as bytes,
* which a loader that read first would then run as a script. So the stat
* probe runs before the read, and asks both channels a backend can answer on,
* since on a prefix store a directory is the set of keys under it rather than
* an object. A stat miss alone proves nothing (absence takes two channels), so
* only a positive directory answer is acted on and the read still owns "no
* such file".
*
* The caller owns the diagnostic: `source` and a nested shell word the same
* failure differently and exit differently on it.
*/
export declare function readScriptBytes(dispatch: DispatchFn, path: string, cwd: string): Promise<Uint8Array>;
/** Read a script file as text, a byte UTF-8 cannot read replaced. */
export declare function readScriptText(dispatch: DispatchFn, path: string, cwd: string): Promise<string>;
export declare function isBinary(data: Uint8Array): boolean;
/**
* Read a script file operand, or the failure bash reports for it.
*
* GNU splits the diagnostics by how far startup got, and both halves fall out
* of the errno rather than being listed case by case. A file the shell cannot
* open at all is blamed on the shell, and only a missing one is exit 127
* (`bash: run.sh: No such file or directory`); anything it found but could not
* run is 126 (`Permission denied`, `Not a directory`). A directory is the
* exception, because it opens fine and fails on the first read, by which point
* `$0` is already the operand, so bash prints it twice (`/tmp: /tmp: Is a
* directory`, exit 126). Reproduced rather than tidied up: it is what an agent
* copying a message into a search box will find.
*/
export declare function readScriptFile(dispatch: DispatchFn, name: string, path: string, session: SessionState): Promise<[string, null] | [null, RedirectResult]>;
//# sourceMappingURL=script.d.ts.map