Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:20000419 Fauxnix PowerShellHost

From Leeroopedia
Knowledge Sources
Domains Process_Management, PowerShell, IPC
Last Updated 2026-10-26 00:00 GMT

Overview

Concrete resident PowerShell process manager that communicates with a long-lived powershell.exe over a JSON-framed, base64-encoded stdio protocol to enable warm repeated invocations without cold-boot cost.

Description

The PowerShellHost class (src/ps-host.ts) owns a single resident PowerShell child process. Instead of spawning a fresh PowerShell per command, fauxnix writes a host script (hostFile) that reads newline-delimited JSON requests from stdin and writes JSON responses to stdout, with command stdout/stderr returned as base64 so Windows PowerShell 5.1's UTF-16LE pipe encoding cannot scramble the payload. ready() starts the process and waits for a ready handshake (prewarm). invoke() sends a script + environment, waits for the result frame, and enforces a timeout. The host supports capture, spool (redirect-to-file), and discard stream modes, plus a native-stderr spool for 2>&1 merged output. An invokeLock serializes calls so a run/reset/dispose cannot interleave with an in-flight invoke.

Usage

This class is created internally by FauxnixSession.ensureHost(); callers do not import it directly. It exists to make the first real command warm (prewarmed at MCP/facade startup) and to persist session state across calls.

Code Reference

Source Location

  • Repository: fauxnix
  • File: src/ps-host.ts
  • Lines: PowerShellHost class at L167+; ready L207-209; invoke L211+; stop (teardown)

Signature

export type HostStreamMode = 'capture' | 'spool' | 'discard';

export class PowerShellHost {
  protocol: 1 | 2;

  constructor(
    hostFile: string,
    envFn: () => NodeJS.ProcessEnv,
    powerShell?: PowerShellSelection,
    nativeSpoolWrite?: NativeSpoolWriter,
  );

  ready(): Promise<HostInvokeResult | null>;
  invoke(script: string, env: HostRequestEnv, timeoutMs: number): Promise<HostInvokeResult>;
  stop(): Promise<void>;
}

Import

import { PowerShellHost, DEFAULT_STDOUT_LIMIT, DEFAULT_STDERR_LIMIT } from './ps-host.js';

I/O Contract

Inputs

Name Type Required Description
script string Yes PowerShell script to execute
env HostRequestEnv Yes Child process environment (cwd, stdin file, prev exit)
timeoutMs number Yes Per-invoke timeout

Outputs

Name Type Description
invoke returns HostInvokeResult stdout (Buffer), stderr (Buffer), exitCode, ready flag

Usage Examples

Internal: Prewarm via FauxnixSession

// Callers use FauxnixSession, which owns the host:
const session = new FauxnixSession();
await session.prewarm();   // PowerShellHost.ready() under the hood

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment