/** * Script runner for rill-run. * Builds runtime options, executes rill scripts, and maps results to exit codes. */ import { type RillValue, type RillStream, type RuntimeContext, type SchemeResolver } from '@rcrsr/rill'; import { RillError } from '@rcrsr/rill'; import type { RillConfigFile } from '@rcrsr/rill-config'; import type { RunCliOptions } from './types.js'; export interface RunResult { readonly exitCode: number; readonly output?: string | undefined; readonly errorOutput?: string | undefined; } /** * Format a RillError for stderr output, preserving atom code, message, * source-aware snippet, and trace chain across human / json / compact * formats. * * RuntimeError instances carrying a halt view route through the * enriched formatError path (snippet + trace block). Other RillError * subclasses fall back to formatRillError / formatRillErrorJson. */ export declare function formatRillErrorOutput(err: RillError, source: string, scriptPath: string, opts: Pick): string; /** * Format any error thrown by handler-mode evaluation: RuntimeHaltSignal * (raw halts that escape invokeCallable without RuntimeError wrapping), * RillError instances, or arbitrary Error subclasses. * * Module mode never sees RuntimeHaltSignal because execute() converts * escaping halts to RuntimeError. Handler mode invokes closures via * invokeCallable directly, so halts surface as RuntimeHaltSignal whose * default Error message is the literal string "runtime halt"; this * helper extracts the halt view from signal.value and renders the same * envelope module mode produces. */ export declare function formatHandlerError(err: unknown, source: string, scriptPath: string, opts: Pick): string; /** * Build a custom module scheme resolver using folder aliasing. * Each config key maps to a directory. Dot-paths resolve to files within: * - `module:alias.sub.path` → `{dir}/sub/path.rill` * - `module:alias` → `{dir}/index.rill` */ export declare function buildModuleResolver(modulesConfig: Record, configDir: string): SchemeResolver; /** * Walk a RillStream linked list, collect all chunk values, then call dispose. * When onChunk is provided, each chunk is emitted immediately for streaming output * and collection is skipped to avoid unbounded memory growth. * Returns the collected chunks as an array (empty when onChunk is provided). */ export declare function drainStream(stream: RillStream, ctx: RuntimeContext, onChunk?: (value: RillValue) => void | Promise): Promise; /** * Create an onChunk callback that writes stream chunks to stdout, * respecting the output format and handling backpressure. */ export declare function createStreamWriter(format: RunCliOptions['format']): { onChunk: (value: RillValue) => Promise; finalize: () => Promise; }; export declare function formatOutput(value: RillValue, format: RunCliOptions['format']): string; /** * Run a rill script file with the given extension tree and config. */ export declare function runScript(opts: RunCliOptions, config: RillConfigFile, extTree: Record, disposes: Array<() => void | Promise>): Promise;