Skip to content

RuntimeAdapter ​

Runtime adapter interface.

Defines the minimal contract between the platform-agnostic core and the host runtime (Node.js, Bun, Deno). Every platform-dependent operation flows through this interface — the core never calls process.*, Deno.*, or Bun.* directly.

Adapters are designed to be:

  • Immutable in shape: all properties are readonly

  • Minimal: only the operations the framework actually needs

  • Testable: easily stubbed in tests via createTestAdapter()

  • Import: @kjanat/dreamcli/runtime

  • Export kind: interface

  • Declared in: src/runtime/adapter.ts

  • Source link: src/runtime/adapter.ts:39

Signatures ​

ts
interface RuntimeAdapter {}

Members ​

Properties ​

argv ​

Raw argv array (including binary + script path, e.g. ['node', 'cli.js', 'deploy']).

ts
argv: readonly string[];

env ​

Environment variables. Values are string | undefined — mirrors Node's process.env semantics.

ts
env: Readonly<Record<string, string | undefined>>;

cwd ​

Current working directory (absolute path).

ts
cwd: string;

stdout ​

Writer for stdout. Framework routes out.log/out.info through this.

ts
stdout: WriteFn;

stderr ​

Writer for stderr. Framework routes out.warn/out.error through this.

ts
stderr: WriteFn;

flush ​

Wait for pending output writes to settle, rejecting with a recorded output failure.

ts
flush?: { (): Promise<void>; };

stdin ​

Line reader for stdin. Used by the prompt engine for interactive input.

Returns null on EOF (Ctrl+D on Unix, Ctrl+Z on Windows), indicating the user closed the input stream (treated as cancel).

ts
stdin: ReadFn;

readSecret ​

Hidden terminal input. Absent when echo suppression is unsupported.

ts
readSecret?: ReadFn;

readStdin ​

Read all of stdin as a single string (for piped data).

Returns the full stdin contents when data is piped (stdinIsTTY is false), or null when stdin is a TTY (no piped data available).

Used by the resolve chain for args with .stdin() configured. Unlike stdin (which reads one line for prompts), this consumes the entire stream to EOF.

ts
readStdin: { (): Promise<string | null>; };

isTTY ​

Whether stdout is connected to a TTY.

ts
isTTY: boolean;

stdinIsTTY ​

Whether stdin is connected to a TTY (used for prompt gating).

ts
stdinIsTTY: boolean;

getTerminalSize ​

Read current terminal dimensions for stdout, if available.

ts
getTerminalSize: { (): TerminalSize | undefined; };

onTerminalResize ​

Subscribe to terminal resize events when the runtime supports them.

ts
onTerminalResize: { (listener: { (): void; }): { (): void; } | undefined; };

exit ​

Exit the process with the given code. Must not return (divergent function).

ts
exit: { (code: number): never; };

readFile ​

Read a file as UTF-8 text.

Returns file contents on success, null if the file does not exist (ENOENT/NotFound). Throws on other I/O errors (permission denied, is-directory, etc.) — those indicate unexpected failures, not "try the next path".

Used by config file discovery to probe multiple candidate paths.

ts
readFile: { (path: string): Promise<string | null>; };

configFileExists ​

Probe a path-loader candidate without reading its contents. Explicit paths report access errors.

ts
configFileExists?: { (path: string, explicit: boolean): Promise<boolean>; };

importConfigModule ​

Import a local executable config and return its default export.

ts
importConfigModule?: { (path: string): Promise<unknown>; };

importFreshConfigModule ​

Evaluate a config in a new module graph and return its data to this host.

ts
importFreshConfigModule?: { (path: string, timeoutMs?: number): Promise<unknown>; };

stat ​

Probe what exists at a filesystem path.

Returns 'file' or 'directory' for existing paths (other kinds such as sockets report 'file'), or null when nothing exists there.

Used by flag.path() existence/type checks after resolution.

ts
stat: { (path: string): Promise<"file" | "directory" | null>; };

mkdir ​

Create a directory, including missing parents.

Succeeds when the directory already exists. Throws on other I/O errors (permission denied, existing file at the path, etc.).

Used by flag.path() create checks after resolution.

ts
mkdir: { (path: string): Promise<void>; };

homedir ​

User home directory (absolute path).

  • Node/Bun: derived from HOME / USERPROFILE env
  • Deno: Deno.env.get('HOME') / Deno.env.get('USERPROFILE')
ts
homedir: string;

configDir ​

Platform-specific user configuration directory (absolute path).

  • Unix: $XDG_CONFIG_HOME or ~/.config
  • Windows: %APPDATA% or ~\AppData\Roaming

Config discovery appends the app-specific subdirectory.

ts
configDir: string;

userConfigDirs ​

User-scope config roots for discovery, highest priority first.

  • Unix: [configDir]
  • macOS: [configDir, ~/Library/Application Support]
  • Windows: [configDir]

When absent, discovery falls back to [configDir].

ts
userConfigDirs?: readonly string[];

systemConfigDirs ​

System-scope config roots for discovery (['/etc'] on Linux and macOS, [] on Windows). When absent, discovery probes none.

ts
systemConfigDirs?: readonly string[];

Examples ​

ts
// Production: auto-detected
cli('mycli').run(); // uses Node/Bun/Deno adapter

// Test: explicit adapter
cli('mycli').run({ adapter: createTestAdapter({ argv: ['deploy'] }) });

See Also ​

Released under the MIT License.