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

Principle:20000419 Fauxnix Source to Source Translation

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

Overview

A source-to-source transpilation technique that walks a parsed bash AST and emits semantically equivalent PowerShell statements following a strict output contract, with two translation modes controlling whether the result is prepared for execution or side-effect-free inspection.

Description

Source-to-Source Translation is the core of fauxnix. Each bash command in the AST is dispatched through a registry to a per-command generator that returns a block of PowerShell statements. The generators follow the "Fauxnix contract": everything emitted is a string line (Unix text-stream semantics, never raw .NET objects), errors go to [Console]::Error.WriteLine with a $script:fx_exit flag (never exit, which would kill sibling pipeline stages), stdin is $input, and output formatting mimics GNU coreutils. The translator supports two modes: EXECUTE_TRANSLATION (output is wrapped for real execution via the persistent host) and PURE_TRANSLATION (side-effect-free, used for preflight validation and the translate CLI verb). Each pipeline segment is wrapped by wrapScript into a self-contained PowerShell script; redirect metadata is collected separately so the executor can prepare file descriptors in source order.

Usage

Use this principle when you need to deterministically convert commands from one shell language to another without an LLM at runtime. The contract-based approach ensures the generated code composes correctly in pipelines and never crashes the host process on a single command failure.

Theoretical Basis

The translation is an AST walk:

for each ListSegment in CommandList:
    for each command in segment.pipeline:
        handler = registry.lookup(command.name)
        if handler: psBlock = handler(command.args, ctx)
        else: passthrough (native argv execution)
    body = defs + "\n" + call
    script = wrapScript(body)
    collect redirects (outputRedirects, stdinRedirects)

The two modes differ only in whether wrapScript adds execution-only wrappers. The contract (string-per-line, Error.WriteLine, $script:fx_exit) is what makes multi-stage pipelines safe: a failing stage sets the flag without exiting the process.

Related Pages

Implemented By

Page Connections

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