@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
64 lines • 2.96 kB
TypeScript
import type { Context } from '../commands/config.ts';
import type { FlagValue } from '../commands/spec/types.ts';
import { PathSpec } from '../types.ts';
import type { Program, RunResult } from './types.ts';
export declare const STDIN_OPERAND = "-";
/**
* What an interpreter calls itself in the entry points with no file name.
*
* They differ per interpreter, not per language: CPython puts '-c' in
* argv[0] for a payload, while qjs leaves scriptArgs alone for `-e`.
*/
export interface Argv0Rules {
/** argv[0] for a -c/-e payload. */
readonly payload?: string;
/** argv[0] for an explicit "-" operand. */
readonly stdinOperand?: string;
/** argv[0] for a program piped in with no operand at all. */
readonly bareStdin?: string;
/** File mode puts the operand in argv[0]; false for qjs. */
readonly namesFile?: boolean;
}
/**
* Drop a script's first line the way CPython's `-x` does.
*
* The first line is emptied rather than removed, because CPython keeps
* the line numbering of the whole file: a raise on physical line 2
* still reports line 2 under `-x` (pinned on 3.12.11). A file with no
* newline at all is one line, so `-x` leaves nothing.
*
* @param code the script's text as read.
*/
export declare function skipFirstLine(code: string): string;
/**
* The script an interpreter's operands name, null when the program comes
* from `-c`, `-m` or stdin. The exec check and the runtime both ask it.
*
* @param paths the path operands.
* @param texts the text operands.
* @param flags the interpreter switches.
* @param cwd the working directory a text operand resolves against.
*/
export declare function scriptOperand(paths: readonly PathSpec[], texts: readonly string[], flags: Readonly<Record<string, FlagValue>>, cwd: PathSpec | string | null): PathSpec | null;
/**
* Resolve what a language runtime runs from its operands, as a real
* interpreter does.
*
* `-c` wins, else `-m` names a module, else the first operand is the
* script (read through `ctx.vfs`), else piped stdin is the program. A
* script CLI names itself `ctx.spec.name`.
*
* @param paths the path operands.
* @param texts the text operands.
* @param ctx the run's context; `flags` holds the switches (`c`, `m`,
* `x`, `scriptCli`).
* @param label the command name the messages use.
* @param rules what this interpreter calls itself in the entry points
* that carry no file name.
* @param moduleCode the program a `-m` runs, given the module and the
* label; null when this runtime cannot run a module.
* @param runtimeName the runtime's name, for the `-m` refusal.
* @returns the program, or why nothing ran.
*/
export declare function resolveProgram(paths: readonly PathSpec[], texts: readonly string[], ctx: Context, label: string, rules: Argv0Rules, moduleCode: (name: string, label: string) => string | null, runtimeName: string): Promise<Program | RunResult>;
//# sourceMappingURL=source.d.ts.map