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 FauxnixSession

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

Overview

Concrete session class that spawns and manages a persistent PowerShell host, executes translated SegmentPlan arrays with timeout/cancellation/output budgets, and persists cwd, env, and positional parameters across calls like a real shell.

Description

The FauxnixSession class is the execution backbone of fauxnix. On construction it resolves the PowerShell host via resolvePowerShell() and binds temp files for cwd/env tracking. It lazily creates a PowerShellHost (src/ps-host.ts) — a resident PowerShell process communicating over a JSON-framed, base64-encoded protocol — enabling warm calls (~30–50 ms) instead of cold-boot seconds. The run method executes a SegmentPlan[] with bash list semantics (&&/||/;), redirect preparation, output clipping to byte budgets, and stderr normalization. The runBatch method executes multiple precompiled plan groups atomically in one session turn with shared timeout and output budgets. prewarm boots the host early; reset kills and re-prewarms; dispose tears down the host and temp files. Session state (cwd, env, prevExit) is synced from disk after each segment and layered into the child process environment.

Usage

  • CLI one-shot: construct a FauxnixSession, call run once, then dispose.
  • MCP server: construct once at startup, prewarm, then reuse across bash/bash_batch tool calls for state persistence.
  • Differential runner: prewarm before the corpus loop, run per case, dispose after.
  • Facade: construct for one-shot or marker-session execution.

Code Reference

Source Location

  • Repository: fauxnix
  • File: src/executor.ts
  • Lines: FauxnixSession class L290-513; run L429-433; runBatch L440-513; prewarm L359-363; reset L370-375; dispose L365-367; runPlans L515+

Signature

export interface ExecResult {
  stdout: string;
  stderr: string;
  exitCode: number;
  timedOut: boolean;
  cancelled: boolean;
  truncated: boolean;
  stdoutTruncated?: boolean;
  stderrTruncated?: boolean;
  infrastructureError?: boolean;
  spawnError?: 'ENOENT' | 'START';
}

export interface ExecOptions {
  timeoutMs?: number;
  cwd?: string;
  signal?: AbortSignal;
  stdoutLimit?: number;
  stderrLimit?: number;
}

export interface BatchExecOptions extends ExecOptions {
  stopOnError?: boolean;
}

export interface BatchExecResult {
  results: ExecResult[];
  stopReason: 'completed' | 'command_failed' | 'timed_out' | 'cancelled' | 'infrastructure';
}

export class FauxnixSession {
  id: string;
  cwd: string | null;
  env: Record<string, string>;
  prevExit: number | null;

  constructor();

  prewarm(): Promise<void>;
  dispose(): Promise<void>;
  reset(): Promise<void>;

  run(plans: SegmentPlan[], opts?: ExecOptions): Promise<ExecResult>;
  runBatch(planGroups: SegmentPlan[][], opts?: BatchExecOptions): Promise<BatchExecResult>;

  childEnv(cwdOverride?: string, stdinFile?: string | null): NodeJS.ProcessEnv;
}

Import

import { FauxnixSession, ExecResult, ExecOptions, BatchExecResult } from './executor.js';

I/O Contract

Inputs

Name Type Required Description
plans SegmentPlan[] Yes Translated segments from translateCommandList
opts.timeoutMs number No Per-run timeout (default 120000 ms)
opts.cwd string No Override the session cwd for this call
opts.signal AbortSignal No Abort signal for cancellation
opts.stdoutLimit number No Caller stdout byte budget
opts.stderrLimit number No Caller stderr byte budget
(runBatch) opts.stopOnError boolean No Stop after first nonzero exit (default true)

Outputs

Name Type Description
run() returns ExecResult stdout, stderr, exitCode, timedOut, cancelled, truncated flags
runBatch() returns BatchExecResult Per-step ExecResult[] plus a stopReason

Usage Examples

One-Shot CLI Execution

const session = new FauxnixSession();
try {
  const result = await session.run(plans);
  if (result.stdout) process.stdout.write(result.stdout);
  if (result.stderr) process.stderr.write(result.stderr);
  process.exitCode = result.exitCode;
} finally {
  await session.dispose();
}

Prewarm for Warm MCP Calls

const session = new FauxnixSession();
await session.prewarm();   // host booted before first tool call
// ... repeated session.run() calls persist cwd/env ...

Batch Execution

const compiled = compileBatchSteps(steps);   // SegmentPlan[][]
const batch = await session.runBatch(compiled, {
  stopOnError: true,
  timeoutMs: 60000,
  stdoutLimit: 262144,
  stderrLimit: 65536,
});
// batch.results[i] per step; batch.stopReason → 'completed' | 'command_failed' | ...

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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