Skip to content

@kjanat/dreamcli/runtime

Runtime adapter factory and platform detection.

ts
import {
  createAdapter,
  detectRuntime,
} from '@kjanat/dreamcli/runtime';
import type { RuntimeAdapter, TerminalSize } from '@kjanat/dreamcli/runtime';

createAdapter()

Create a runtime adapter via auto-detection.

ts
import {
  createAdapter,
  createNodeAdapter,
  createDenoAdapter,
} from '@kjanat/dreamcli/runtime';

const adapter = createAdapter(); // auto-detect
const nodeAdapter = createNodeAdapter(); // explicit Node.js (also used for Bun)
const denoAdapter = createDenoAdapter(); // explicit Deno

Bun exposes a Node-compatible process, so it uses the Node adapter — there is no separate Bun factory. Runtime detection still reports 'bun' (see detectRuntime()).

RuntimeAdapter Interface

MemberKindDescription
argvreadonlyRaw command-line arguments
envreadonlyEnvironment variables
cwdreadonlyCurrent working directory
stdoutreadonlyStdout writer used by the output channel
stderrreadonlyStderr writer used by the output channel
stdinreadonlyLine reader used for interactive prompts
readStdin()methodRead all piped stdin as a single string, or null when stdin is a TTY / no data is piped
isTTYreadonlyWhether stdout is connected to a TTY
stdinIsTTYreadonlyWhether stdin is connected to a TTY
getTerminalSize()methodRead current stdout terminal dimensions, or undefined when unavailable
onTerminalResize(listener)methodSubscribe to terminal resize events when supported
exit(code)methodExit the process
readFile(path)methodRead a UTF-8 file for config discovery
homedirreadonlyUser home directory
configDirreadonlyPlatform-specific configuration directory

TerminalSize is { columns: number; rows: number }. Node and Bun read process.stdout.getWindowSize() when available, falling back to columns / rows. Deno uses Deno.consoleSize().

detectRuntime()

Detect the current runtime environment.

ts
import { detectRuntime } from '@kjanat/dreamcli/runtime';
import type { Runtime } from '@kjanat/dreamcli/runtime';

const runtime: Runtime = detectRuntime();

Supported Runtimes

RuntimeAdapterNotes
Node.js >= 22.22.2NodeAdapterFull support
Bun >= 1.3NodeAdapterUses Node-compatible process
Deno >= 2.6.0DenoAdapterPermission-safe Deno namespace

These minimums are the tested support floor, declared in the package engines field. Adapter creation does not validate the runtime version or throw: as a dependency the package manager enforces engines at install time, and when DreamCLI is bundled the consuming CLI owns its supported-runtime policy.

Released under the MIT License.