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: packages/dreamcli/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[];

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;

cwd

Current working directory (absolute path).

ts
cwd: string;

env

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

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

exit

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

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

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;

isTTY

Whether stdout is connected to a TTY.

ts
isTTY: boolean;

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>; };

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>; };

stderr

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

ts
stderr: WriteFn;

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;

stdinIsTTY

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

ts
stdinIsTTY: boolean;

stdout

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

ts
stdout: WriteFn;

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.