Skip to main content
Glama

fauxnix

CI npm version npm downloads license 20000419/fauxnix MCP server

在 Windows 上以原生、确定性的方式运行 Linux 风格命令——无需虚拟机,无需 WSL。

fauxnix 是专为 AI 代理打造的 bash→PowerShell 翻译层。你的代理可以继续编写它已经熟悉的 bash 命令(ls -la | grep foo、find . -name '*.ts' | wc -l、kill -9 1234),fauxnix 会确定性地将每条命令翻译成 PowerShell,原生执行,并返回看起来像 GNU/Linux 的输出:ls -l 列、bash 风格错误消息、coreutils 退出码,UTF-8/GBK 自动处理。

npm install -g fauxnix-cli    # then point any MCP harness at `fauxnix mcp`

fauxnix demo

$ fauxnix "ls -la src | head -2"
-rw-r--r-- 1 me me 1204 Aug 16 09:12 ast.ts
-rw-r--r-- 1 me me 8192 Aug 16 09:12 cli.ts

$ fauxnix "cat nope.txt"
cat: nope.txt: No such file or directory        # not a PowerShell stack trace

实测:你的模型在 PowerShell 上的表现可能比你想的更差

同一模型(DeepSeek-V4-Pro)、同样的 5 个任务、同一台 Windows 机器上的三种执行模式——完整数据见 docs/benchmark-deepseek-v4-pro.md 和 `docs/benchmark-ark-models.md:

PowerShell

fauxnix

Git Bash

工具调用 / 意外错误

14 / 9

7 / 0

4 / 0

时间(T1–T4)

163s

66s

57s

在 Volcano Ark Coding Plan 的 7 个模型中,PowerShell 与 fauxnix 之间的差距在每个测试模型上都成立——最坏情况(kimi-k2-thinking):手写 PowerShell 比 fauxnix 慢 3.1 倍,并产生 24 个错误事件,而通过 fauxnix 零错误。在未安装任何 bash 工具链的情况下,fauxnix 也能落在真实 bash 上限的 ~15% 以内。

Related MCP server: wmux

为什么

LLM 代理在 bash 上的表现远优于 PowerShell——bash 在训练数据中占主导,因此 Windows 上的模型常常生成“看起来对、跑不起来”的命令(错误的引号、不是 curl 的 curl、代码页不匹配导致的乱码、令人费解的 CategoryInfo 错误转储)。现有解决方案要么是完整的虚拟机(WSL——笨重、文件系统不对、环境隔离),要么是单纯的 shell 包装器(底层仍是 PowerShell)。

fauxnix 走的是第三条路:翻译,而非模拟。Linux 命令行中一个庞大且高价值的子集——文件操作、文本处理、进程管理、归档、基础网络——可以干净地映射到 PowerShell + .NET。fauxnix 忠实实现了这一子集,并在无法翻译时响亮且有益地失败,因此代理永远不会得到悄悄出错的结果。

安装

npm install -g fauxnix-cli

或者从源码构建:

git clone https://github.com/20000419/fauxnix && cd fauxnix && npm install -g .

npm 包名是 fauxnix-cli(npm 上的 fauxnix 名称属于一个无关的 2015 年 websocket 库);安装后的命令仍然是 fauxnix。

要求:Windows(自带 PowerShell 5.1+)和 Node.js ≥ 18。

快速开始

# one-off commands
fauxnix "ls -la"
fauxnix "grep -rn TODO src | wc -l"
fauxnix "cat log.txt | grep -i error | sort | uniq -c"

# see what a command becomes (great for debugging / learning PS)
fauxnix translate "find . -name '*.log' -mtime +7 -delete"

# check your environment
fauxnix check

# run the MCP stdio server (what agent harnesses connect to)
fauxnix mcp

未知命令(git、node、npm、python、cargo、gh、docker……)会以 argv 风格引用原生透传——不重新解析字符串,也没有引号 bug。

配合你的代理框架使用

fauxnix 附带一个 MCP stdio 服务器,提供 bash 工具(另有 fauxnix_translate 和 fauxnix_session)。任何支持 MCP 的框架都可以接入:

Claude Code

claude mcp add fauxnix -- fauxnix mcp

Codex(~/.codex/config.toml 或 codex mcp add fauxnix -- fauxnix mcp)

[mcp_servers.fauxnix]
command = "fauxnix"
args = ["mcp"]

注意:在非交互式 codex exec 模式下,MCP 工具调用会被审批层自动拒绝;请传入 --dangerously-bypass-approvals-and-sandbox(或以交互方式运行并批准一次)。

OpenCode(opencode.json)

{
  "mcp": {
    "fauxnix": { "type": "local", "command": ["fauxnix", "mcp"] }
  }
}

Kimi Code——与其他工具不同,MCP 服务器位于 JSON 文件而不是 TOML 配置中:~/.kimi-code/mcp.json

{
  "mcpServers": {
    "fauxnix": { "command": "fauxnix", "args": ["mcp"] }
  }
}

任意 MCP 客户端——stdio 服务器:fauxnix mcp。工具名称是 bash(可通过 FAUXNIX_TOOL_NAME 覆盖)。工具描述已经教会了模型所支持的子集,因此无需改动系统提示词。

MCP 会话会在工具调用之间持久保留 cwd、环境变量、export/unset 以及 cd -/OLDPWD——它的行为像一个已登录的 shell,而不是无状态的 exec。

支持的命令

~105 条命令,开发时所有输出均在 Windows(Git Bash)上与真实 GNU coreutils 逐一对齐:

  • 文件:ls cp mv rm mkdir rmdir touch mktemp ln readlink realpath basename dirname stat file du df find chmod chown diff

  • 文本过滤:grep egrep sed awk sort uniq cut tr——sed/awk 脚本在翻译时解析(不支持的构造会抛出命名错误,绝不会悄悄出错)

  • 文本 I/O:echo printf cat head tail wc tee nl tac md5sum sha1sum sha256sum base64 seq yes xargs

  • shell/系统:cd pwd export unset env printenv ps kill pkill pgrep sleep which type whoami id groups date uname hostname uptime free nproc clear true false test [ [[ : pushd popd dirs sudo timeout man history less more source . eval exit alias set

  • 网络:curl wget ping netstat ss ip ifconfig nslookup dig host

  • 归档:tar gzip gunzip zcat zip unzip

此外还支持 shell 语法:管道、&& / || / ;、重定向(> >> 2> 2>&1 < &>、/dev/null)、引号、$VAR $(...) 命令替换、VAR=x cmd 前缀、~ 展开,以及 POSIX 风格路径归一化(/tmp、/d/foo → D:\foo)。

退出码遵循 bash 约定:0 成功、1 失败、2 用法错误/严重错误、127 命令未找到、124 超时。

工作原理

bash command ──parser──▶ AST ──translator──▶ PowerShell script ──executor──▶ powershell.exe
                                                                              │
agent ◀── GNU-style output, bash-style errors ◀── decoder (UTF-8 → GBK fallback) ◀┘
  • 确定性翻译,运行时零 LLM 调用。

  • 每条命令映射到一个生成器,生成自包含的 PowerShell 块,遵守“Fauxnix 契约”:stdout 逐行字符串,bash 风格 stderr 使用 [Console]::Error.WriteLine,退出码使用 $script:fx_exit,stdin 使用 $input。

  • 执行器会用 UTF-8 强制包裹每个脚本([Console]::OutputEncoding、$OutputEncoding、chcp 65001),输出按严格 UTF-8 解码,并为旧式原生工具提供 GBK(936) 回退;从 stderr 中剥离 CLIXML 序列化和 PowerShell 噪音,并把常见的 PowerShell 错误(包括 zh-CN 区域设置消息)改写成 bash 措辞。

  • 脚本通过 -EncodedCommand(UTF-16LE)运行,并在可能超过 32 KB 命令行限制时透明地回退到临时 .ps1 文件。

已知差异(诚实清单)

fauxnix 针对代理真正会运行的命令做了优化。以下是已记录的差异:

  • X=1 独立赋值遵循 export 语义(整个会话共用一个环境;bash 中 shell 变量与导出变量的区别在这里不存在),且同一命令前缀对命令自身单词内的 $VAR 可见(Z=in [[ $Z == in ]] 在这里为真,在 bash 中为假,因为 bash 的单词展开先于临时环境)。

  • yes 最多输出 65,536 行——PS 5.1 管道无法通知上游生产者停止,因此无上限的 yes | head 会挂起。

  • tail -f、eval、alias、heredoc、while/until/case、词级 $((...)) 算术展开和后台 & 会被拒绝,并给出可操作的错误消息,而不是错误行为。(if/then/else/fi、for x in ...、反引号替换、command -v、管道 read 和 dotenv 风格的 source 受支持。)

  • command -v <builtin> 会输出 /usr/bin/<name>,而 bash 输出的是裸的内置命令名;退出码和空结果语义一致。

  • chmod 只映射只读位;exec 位在 Windows 上是空操作。chown 是静默空操作(与 Git Bash 一样)。

  • ps aux 的列是近似值(没有按进程的 CPU% 统计,USER 显示为 ?)。

  • gzip -c/管道 stdin 是文本保真,而非字节保真;文件模式 gzip f 是字节精确的。

  • 一个恰好产生一行的管道,接到 wc -l 时会计入这一行(如果生产者省略了末尾换行符,bash 会计为 0)。printf 'x' | md5sum 仍保持字节精确。

  • sed/awk 支持常见子集;hold-space、标签、数组、循环会在翻译时抛出命名“不支持”错误。

  • curl/wget 默认拒绝回环/私有/保留地址(localhost、127.x、::1、10.x、172.16–31.x、192.168.x、169.254.x),作为代理驱动 HTTP 的安全默认。

  • 原生工具管道与编码:PS 5.1 只有一个控制台编码旋钮,因此将本地化管理工具(ipconfig、tasklist——zh-CN 下为 GBK)和 UTF-8 原生的开发工具(node、curl)接入同一管道时,无法在管道中途同时干净地解码。默认优先 UTF-8 开发工具;当你的代理需要 grep 原生 Windows 管理工具的中文输出时,设置 FAUXNIX_NATIVE_ENCODING=ansi。文件读取始终按文件嗅探(严格 UTF-8 → GBK 回退),因此对 GBK 文件 执行 grep/sed/awk 在任一模式下都能工作——这与 Git Bash 不同,后者只匹配其区域设置所假定的编码。

开发

npm install
npm test          # unit + real-PowerShell integration suite (Windows only, auto-skipped elsewhere)
npm run build
npx tsx scratch/run.mjs "any bash command"   # quick live check

架构地图:src/parser.ts(bash 子集 → AST)· src/translator.ts(AST → PowerShell + 执行器包装)· src/executor.ts(spawn、重定向、会话持久化)· src/commands/*.ts(每条命令的生成器)· src/mcp.ts(MCP 服务器)· src/cli.ts。

许可证

MIT © 20000419

Available Tools

4 tools
bashA
Destructive

Execute a Linux/bash-style command on this Windows machine.

Commands are deterministically translated to PowerShell and executed natively — no WSL or VM. Output is formatted to look like GNU/Linux tooling (ls -l, ps aux, df -h ...), errors look like bash errors, and text encoding (UTF-8/GBK) is handled automatically.

Supported: pipes (|), && / || / ;, redirections (> >> 2> 2>&1 < /dev/null), variables ($VAR $HOME $1 $# "$@" ~), set -- / shift, array assignment A=(x y z), ${name[n]} ${#name[@]} ${name//pat/str} ${name:off:len}, command substitution $(...), and 109+ coreutils-style commands (., :, [, [[, alias, awk, base64, basename, cat, cd, chmod, chown, clear, command, cp, curl, cut, date...). Unknown commands (git, node, npm, python, cargo...) are passed through and executed natively with argv-style quoting. Not supported: heredocs, env -i/--ignore-environment, background jobs. if/then/elif/else/fi, for-in loops, while/until, case ... esac, and word-level $((...)) arithmetic expansion are supported. CWD, environment variables, export/unset, cd, and positional parameters (set -- / $1 / "$@") persist across calls within this session — a resident PowerShell 5.1 host is started when the MCP session begins (and after reset), so the first bash tool call is already warm. Efficiency: when two or more commands or verification steps are already known, prefer bash_batch once instead of making several bash calls. Keep separate calls only when the next command requires model interpretation of the previous output. For byte-exact work, measure with wc -c or stat -c %s instead of inferring CRLF byte counts from displayed text. MCP capture is bounded to 256 KiB stdout and 64 KiB stderr across the complete command list; larger output is marked truncated. Redirect larger artifacts to files. These transport-safe budgets include room for JSON escaping and duplicate text/structured fields. Exit codes follow bash conventions (0 ok, 1 fail, 2 usage/serious, 127 command not found, 124 timeout, 130 cancelled). The tool also returns structuredContent (schemaVersion 1) with stdout/stderr/exitCode/timedOut/cancelled/truncated/sessionId.

Platform requirement: the execution backend is native Windows PowerShell 5.1+. On hosts without PowerShell on PATH (e.g. Linux containers/sandboxes), the bash tool returns exit code 127 with an actionable error instead of running the command.

Inputs: command (required), timeout_ms.

bash_batchA
Destructive

Compile and execute a preplanned multi-step bash workflow in one MCP round trip.

Use this instead of repeated bash calls when the complete sequence is already known. Steps run serially and atomically in the same persistent session: later steps see cwd, environment, and files from earlier steps, while run/reset requests cannot interleave. Every command is parsed and translated before step 1 runs, and the result reports each step separately.

By default the batch stops after the first nonzero exit. Set stop_on_error=false only when later steps should still run. timeout_ms and both output limits apply to the whole batch, not once per step. Output defaults to 256 KiB stdout and 64 KiB stderr; redirect larger artifacts to files. Preflight performs no operand-file reads: use sed -e with inline script text instead of sed -f. If a later command depends on model interpretation of an earlier result, use separate bash calls instead. For byte counts, include wc -c or stat -c %s as a verification step rather than calculating CRLF bytes mentally.

Inputs: steps (required), timeout_ms, stop_on_error, stderr_limit_bytes, +1 more.

fauxnix_sessionA
Idempotent

Inspect or reset the persistent fauxnix shell session (current directory, environment, positional count, session id). Actions: "status" (default) or "reset".

Inputs: action.

fauxnix_translateA
Read-onlyIdempotent

Translate a bash-style command into the equivalent PowerShell script WITHOUT executing it. Useful for learning/debugging what fauxnix does under the hood.

Inputs: command (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 4 tools

    Disambiguation4/5

    bash and bash_batch overlap in purpose (both execute commands), but the descriptions give clear guidance on when to use each (batch for preplanned sequences, separate calls when model interpretation is needed). fauxnix_session and fauxnix_translate are clearly distinct. Only minor risk of misselection between the two execution tools.

    Naming Consistency3/5

    Two naming families coexist: bare 'bash'/'bash_batch' (shared prefix, but no verb_noun form) and 'fauxnix_session'/'fauxnix_translate' (server-prefixed). The pattern is readable and not chaotic, but conventions are mixed rather than uniform.

    Tool Count5/5

    Four tools is well-scoped for a shell-emulation server: execution, batched execution, session inspection, and translation each earn their place with no redundancy.

    Completeness4/5

    The surface covers execution, batch workflows, session status/reset, and translation introspection, which is solid lifecycle coverage for a shell proxy. Minor gap: no direct way to kill or interrupt a running process beyond reset, but core workflows are covered.

    Maintenance

    ActivityMaintained
    ResponsivenessUsually handled

    Related MCP Connectors

    Related MCP Servers