fauxnix-cli 0.12.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
7
  [![20000419/fauxnix MCP server](https://glama.ai/mcp/servers/20000419/fauxnix/badges/score.svg)](https://glama.ai/mcp/servers/20000419/fauxnix)
8
8
 
9
- **Run Linux-style commands on Windows — natively, deterministically, with no VM and no WSL.**
9
+ **Run Linux-style commands on Windows — natively, deterministically, no VM, no WSL.**
10
10
 
11
11
  fauxnix is a bash→PowerShell translation layer built for AI agents. Your agent keeps writing the
12
12
  bash it already knows (`ls -la | grep foo`, `find . -name '*.ts' | wc -l`, `kill -9 1234`), and
@@ -14,8 +14,15 @@ fauxnix deterministically translates each command into PowerShell, executes it n
14
14
  back output that looks like GNU/Linux: `ls -l` columns, bash-style error messages, coreutils exit
15
15
  codes, UTF-8/GBK handled automatically.
16
16
 
17
+ One-command install for **Claude Code · Codex · OpenCode · Kimi Code · Qwen Code**, plus any MCP
18
+ client. **109 translated commands · 400+ automated tests · 253-case differential corpus verified
19
+ against real GNU coreutils · zero LLM calls at runtime.**
20
+
21
+ ## Try it now — no install
22
+
17
23
  ```bash
18
- npm install -g fauxnix-cli # then point any MCP harness at `fauxnix mcp`
24
+ npx fauxnix-cli@latest "ls -la src | head -3"
25
+ npx fauxnix-cli@latest translate "find . -name '*.log' -mtime +7 -delete"
19
26
  ```
20
27
 
21
28
  ![fauxnix demo](docs/assets/demo.svg)
@@ -29,115 +36,23 @@ $ fauxnix "cat nope.txt"
29
36
  cat: nope.txt: No such file or directory # not a PowerShell stack trace
30
37
  ```
31
38
 
32
- ## Measured: your model is probably worse at PowerShell than you think
33
-
34
- Same model (DeepSeek-V4-Pro), same 5 tasks, three execution modes on one Windows machine —
35
- full data in [`docs/benchmark-deepseek-v4-pro.md`](docs/benchmark-deepseek-v4-pro.md) and
36
- [`docs/benchmark-ark-models.md](docs/benchmark-ark-models.md):
37
-
38
- | | PowerShell | **fauxnix** | Git Bash |
39
- |---|---|---|---|
40
- | tool calls / unexpected errors | 14 / 9 | **7 / 0** | 4 / 0 |
41
- | time (T1–T4) | 163s | **66s** | 57s |
42
-
43
- Across 7 models on the Volcano Ark Coding Plan, the PowerShell-vs-fauxnix gap held for every
44
- model tested — worst case (kimi-k2-thinking): **3.1× slower with 24 error events** writing
45
- PowerShell vs zero errors through fauxnix. fauxnix lands within ~15% of the real-bash ceiling
46
- with no bash toolchain installed.
47
-
48
- ## Why
49
-
50
- LLM agents are dramatically better at bash than at PowerShell — bash dominates training data, so
51
- models on Windows often produce "looks right, doesn't run" commands (wrong quoting, `curl` that
52
- isn't curl, mojibake from codepage mismatches, inscrutable `CategoryInfo` error dumps). Existing
53
- solutions are either a full VM (WSL — heavy, wrong filesystem, separate environment) or plain
54
- shell wrappers (still PowerShell underneath).
55
-
56
- fauxnix takes the third road: **translate, don't emulate**. A large, high-value subset of the
57
- Linux command line — file ops, text processing, process management, archives, networking basics —
58
- maps cleanly onto PowerShell + .NET. fauxnix implements that subset faithfully and *fails loudly
59
- and helpfully* on what it can't translate, so the agent never gets silently-wrong results.
60
-
61
- Labs now train computer-use agents on fleets of real desktops. Reporting in 2026 (*The
62
- Information*, widely repeated) has OpenAI buying tens of thousands of Mac mini / Mac Studio
63
- boxes — no screen, no keyboard — to reinforcement-learn agents that click, edit, test, and
64
- run bash workflows, and Anthropic renting Mac minis through AWS for the same class of work.
65
- That scoring environment is macOS. Windows users should not have to install a guest Unix to
66
- keep up: the agent keeps writing bash; fauxnix makes the Windows box answer like the box the
67
- agent was trained on. See [`docs/rfc-computer-use-windows.md`](docs/rfc-computer-use-windows.md).
68
-
69
- ## Install
39
+ ## Connect your agent — one command
70
40
 
71
41
  ```bash
72
42
  npm install -g fauxnix-cli
43
+ fauxnix install --claude # or --codex / --opencode / --kimi / --qwen
44
+ fauxnix doctor # verifies encoding, harness config, and MCP round-trip
73
45
  ```
74
46
 
75
- Or from source:
76
-
77
- ```bash
78
- git clone https://github.com/20000419/fauxnix && cd fauxnix
79
- npm ci
80
- npm install -g .
81
- ```
82
-
83
- > npm package name is `fauxnix-cli` (the `fauxnix` name on npm belongs to an
84
- > unrelated 2015 websocket library); the installed command is still `fauxnix`.
85
-
86
- Requires: Windows with PowerShell 5.1+ (built-in) and Node.js ≥ 18.
87
-
88
- PowerShell 7 is an opt-in, CI-tested tier:
89
-
90
- ```powershell
91
- $env:FAUXNIX_PS = 'pwsh'
92
- fauxnix check # edition: Core
93
- ```
94
-
95
- Set the variable before starting `fauxnix` or its MCP harness; restart the
96
- harness after changing it. Windows PowerShell 5.1 remains the default. Invalid
97
- values and a missing selected executable fail loudly rather than falling back.
98
- The default is pinned below `SystemRoot`; `pwsh.exe` is resolved once from
99
- absolute `PATH` directories, excluding the current working directory.
100
- See [PowerShell 7 support](docs/powershell-7.md).
101
-
102
- ## Quick start
103
-
104
- ```bash
105
- # one-off commands
106
- fauxnix "ls -la"
107
- fauxnix "grep -rn TODO src | wc -l"
108
- fauxnix "cat log.txt | grep -i error | sort | uniq -c"
109
-
110
- # see what a command becomes (great for debugging / learning PS)
111
- fauxnix translate "find . -name '*.log' -mtime +7 -delete"
112
-
113
- # check your environment
114
- fauxnix check
115
- fauxnix doctor # check + encoding, harness config, MCP
116
-
117
- # write user-level MCP config (idempotent; also --codex/--opencode/--kimi/--qwen)
118
- fauxnix install --claude
119
-
120
- # run the MCP stdio server (what agent harnesses connect to)
121
- fauxnix mcp
122
- ```
123
-
124
- `translate` only renders a script and does not read command operands. Because
125
- `sed -f` needs a script file, translate-only mode asks you to use `-e` with
126
- inline script text; normal command execution continues to support `sed -f`.
127
-
128
- Unknown commands (git, node, npm, python, cargo, gh, docker, ...) are **passed through natively**
129
- with argv-style quoting. Windows `.cmd`/`.bat` shims necessarily pass through `cmd.exe`; fauxnix
130
- preserves its supported punctuation and fails loudly for `%`, embedded double quotes, NUL, and
131
- line breaks rather than passing a different argument.
132
-
133
- ## Use with your agent harness
47
+ Idempotent; prints exactly what changed. Manual configurations below if you prefer to edit
48
+ config files yourself.
134
49
 
135
- fauxnix ships an MCP stdio server exposing a `bash` tool (plus `fauxnix_translate` and
136
- `fauxnix_session`). Point any MCP-capable harness at it with
137
- `fauxnix install --claude` (or `--codex` / `--opencode` / `--kimi` / `--qwen`).
138
- Idempotent; prints what changed. Manual configs below.
50
+ > npm package name is `fauxnix-cli` (the `fauxnix` name on npm belongs to an unrelated 2015
51
+ > websocket library); the installed command is `fauxnix`. Requires Windows with PowerShell 5.1+
52
+ > (built-in) and Node.js ≥ 18.
139
53
 
140
- - **Quickstarts** — copy-paste config + a 10-command smoke: [`docs/examples/`](docs/examples/)
54
+ <details>
55
+ <summary><b>Manual config per harness</b></summary>
141
56
 
142
57
  **Claude Code**
143
58
  ```bash
@@ -150,9 +65,9 @@ claude mcp add fauxnix -- fauxnix mcp
150
65
  command = "fauxnix"
151
66
  args = ["mcp"]
152
67
  ```
153
- Note: in non-interactive `codex exec` mode, MCP tool calls are auto-denied by
154
- the approval layer; pass `--dangerously-bypass-approvals-and-sandbox` (or run
155
- interactively and approve once).
68
+ Note: in non-interactive `codex exec` mode, MCP tool calls are auto-denied by the approval
69
+ layer; pass `--dangerously-bypass-approvals-and-sandbox` (or run interactively and approve
70
+ once).
156
71
 
157
72
  **OpenCode** (`opencode.json`)
158
73
  ```json
@@ -163,8 +78,7 @@ interactively and approve once).
163
78
  }
164
79
  ```
165
80
 
166
- **Kimi Code** — unlike the others, MCP servers live in a JSON file, not the
167
- TOML config: `~/.kimi-code/mcp.json`
81
+ **Kimi Code** — MCP servers live in a JSON file, not the TOML config: `~/.kimi-code/mcp.json`
168
82
  ```json
169
83
  {
170
84
  "mcpServers": {
@@ -177,30 +91,96 @@ TOML config: `~/.kimi-code/mcp.json`
177
91
  ```bash
178
92
  fauxnix install --qwen
179
93
  ```
180
- The installer preserves the rest of `settings.json` and writes an absolute
181
- Node + package-entry launcher so Qwen startup does not depend on its working
182
- directory or `PATH` order. See [the Qwen example](docs/examples/qwen.md) for
183
- the generated JSON shape.
94
+ The installer preserves the rest of `settings.json` and writes an absolute Node + package-entry
95
+ launcher so Qwen startup does not depend on its working directory or `PATH` order. See
96
+ [the Qwen example](docs/examples/qwen.md) for the generated JSON shape.
184
97
 
185
98
  **Any MCP client** — stdio server: `fauxnix mcp`. The tool name is `bash` (override with
186
- `FAUXNIX_TOOL_NAME`). Tool description already teaches the model the supported subset, so no
99
+ `FAUXNIX_TOOL_NAME`). The tool description already teaches the model the supported subset, so no
187
100
  system-prompt changes are required.
188
101
 
102
+ Copy-paste quickstarts with a 10-command smoke test per harness: [`docs/examples/`](docs/examples/)
103
+
104
+ </details>
105
+
189
106
  The MCP session persists `cwd`, environment variables, `export`/`unset`, `cd -`/OLDPWD, and
190
107
  positional parameters (`set --` / `$1` / `"$@"`) across tool calls — it behaves like a logged-in
191
- shell, not a stateless `exec`. `$0` is the MCP tool name (`bash` / `FAUXNIX_TOOL_NAME`), not a
192
- Windows path.
108
+ shell, not a stateless `exec`. `$0` is the MCP tool name, not a Windows path.
109
+
110
+ For workflows whose commands are already known, the MCP server also exposes `bash_batch`: it
111
+ compiles every step before execution, runs the plan atomically in one session, and returns one
112
+ structured result per step in a single MCP round trip (stops on first nonzero exit by default).
113
+
114
+ ```json
115
+ {
116
+ "steps": [
117
+ { "id": "write", "command": "printf 'a\\r\\nb' > data.txt" },
118
+ { "id": "measure", "command": "wc -c data.txt" }
119
+ ]
120
+ }
121
+ ```
122
+
123
+ See [compiled MCP batch plans](docs/rfc-mcp-batch-plans.md) for timeout, budget, cancellation,
124
+ and preflight semantics.
125
+
126
+ ## Measured: your model is probably worse at PowerShell than you think
127
+
128
+ Same model (DeepSeek-V4-Pro), same 5 tasks, three execution modes on one Windows machine —
129
+ full data in [`docs/benchmark-deepseek-v4-pro.md`](docs/benchmark-deepseek-v4-pro.md) and
130
+ [`docs/benchmark-ark-models.md`](docs/benchmark-ark-models.md):
131
+
132
+ | | PowerShell | **fauxnix** | Git Bash |
133
+ |---|---|---|---|
134
+ | tool calls / unexpected errors | 14 / 9 | **7 / 0** | 4 / 0 |
135
+ | time (T1–T4) | 163s | **66s** | 57s |
136
+
137
+ Across 7 models on the Volcano Ark Coding Plan, the PowerShell-vs-fauxnix gap held for every
138
+ model tested — worst case (kimi-k2-thinking): **3.1× slower with 24 error events** writing
139
+ PowerShell vs zero errors through fauxnix. fauxnix lands within ~15% of the real-bash ceiling
140
+ with no bash toolchain installed.
141
+
142
+ ## Why
143
+
144
+ LLM agents are dramatically better at bash than at PowerShell — bash dominates training data, so
145
+ models on Windows often produce "looks right, doesn't run" commands (wrong quoting, `curl` that
146
+ isn't curl, mojibake from codepage mismatches, inscrutable `CategoryInfo` error dumps).
147
+
148
+ | | fauxnix | Git Bash | WSL | Raw PowerShell |
149
+ |---|---|---|---|---|
150
+ | agent writes plain bash | ✓ | ✓ | ✓ | ✗ |
151
+ | only needs Node (no bash toolchain / VM) | ✓ | ✗ | ✗ (VM, GBs) | ✓ |
152
+ | native Windows filesystem & environment | ✓ | mostly | ✗ (9P bridge) | ✓ |
153
+ | GNU-exact output, verified | ✓ 253-case differential | ✓ (is GNU) | ✓ | ✗ |
154
+ | CRLF / UTF-8 / GBK traps handled | ✓ | locale-dependent | ✓ | ✗ |
155
+
156
+ **If Git Bash already works for you, keep it** — we literally use it as our differential-testing
157
+ oracle. fauxnix is for when you can't or don't want to ship one: agent fleets where the bash
158
+ toolchain drifts or isn't detected (the [Windows ARM64 Git-Bash detection
159
+ failure](https://github.com/anthropics/claude-code/issues/73461) is a live example), CI runners,
160
+ locked-down machines, or anywhere a single `npm install -g` is easier than a toolchain.
161
+
162
+ fauxnix takes the third road: **translate, don't emulate**. A large, high-value subset of the
163
+ Linux command line — file ops, text processing, process management, archives, networking basics —
164
+ maps cleanly onto PowerShell + .NET. fauxnix implements that subset faithfully and *fails loudly
165
+ and helpfully* on what it can't translate, so the agent never gets silently-wrong results.
166
+ That matters as labs train computer-use agents on Mac fleets — the agent keeps writing bash;
167
+ fauxnix makes the Windows box answer like the box the agent was trained on
168
+ ([RFC: computer-use parity](docs/rfc-computer-use-windows.md)).
193
169
 
194
170
  ## What's translated
195
171
 
196
- ~105 commands, all output-matched against real GNU coreutils on Windows (Git Bash) during
197
- development:
172
+ 109 commands, output-matched against real GNU coreutils on Windows (Git Bash) during development:
198
173
 
199
174
  - **files**: `ls cp mv rm mkdir rmdir touch mktemp ln readlink realpath basename dirname stat file du df find chmod chown diff`
200
175
  - **text filters**: `grep egrep sed awk sort uniq cut tr` — sed/awk scripts are parsed while
201
176
  preparing an executable plan (unsupported constructs throw named errors, never silently
202
- misbehave); inspect-only `translate` keeps `sed -f` file reads out of that path
177
+ misbehave)
203
178
  - **text I/O**: `echo printf cat head tail wc tee nl tac md5sum sha1sum sha256sum base64 seq yes xargs`
179
+ - **shell/system**: `cd pwd export unset env printenv ps kill pkill pgrep sleep which type whoami
180
+ id groups date uname hostname uptime free nproc clear true false test [ [[ : pushd popd dirs sudo
181
+ timeout man history less more source . eval exit alias set shift`
182
+ - **network**: `curl wget ping netstat ss ip ifconfig nslookup dig host`
183
+ - **archives**: `tar gzip gunzip zcat zip unzip`
204
184
 
205
185
  The curated **agent-daily 60** carry a `CommandSpec`: unknown options fail with a GNU-style
206
186
  usage error instead of being ignored. The generated [`docs/command-specs.md`](docs/command-specs.md)
@@ -210,20 +190,18 @@ compile; `sed`/`awk`/`egrep` keep their command-specific parsers; `tar` remains
210
190
  `tar.exe` so supported bsdtar options reach the executable. Implemented GNU holes include
211
191
  `cp -n` / `mv -n` / `touch -c` / `tee --append` / `grep -m` / `head --lines` /
212
192
  `du --max-depth` / `env -u` / `ps -f` / `command -V` / `date --date=@SECONDS`.
213
- - **shell/system**: `cd pwd export unset env printenv ps kill pkill pgrep sleep which type whoami
214
- id groups date uname hostname uptime free nproc clear true false test [ [[ : pushd popd dirs sudo
215
- timeout man history less more source . eval exit alias set shift`
216
- - **network**: `curl wget ping netstat ss ip ifconfig nslookup dig host`
217
- - **archives**: `tar gzip gunzip zcat zip unzip`
218
193
 
219
194
  Plus shell syntax: pipes, `&&` / `||` / `;`, redirections (`> >> 2> 2>&1 < &>`, `/dev/null`),
220
195
  quoting, `$VAR` `$1` `$#` `"$@"` `set --` `shift`, `${name:-word}` `${name//pat/str}`
221
196
  `${name:off:len}` `${name[n]}` `${#name[@]}`, `A=(x y z)` array assignment, `$(...)` command
222
197
  substitution, `VAR=x cmd` prefixes, `~` expansion, and POSIX-style path normalization
223
- (`/tmp`, `/d/foo` → `D:\foo`).
198
+ (`/tmp`, `/d/foo` → `D:\foo`). Exit codes follow bash conventions: 0 ok, 1 fail, 2 usage/serious,
199
+ 127 command not found, 124 timeout.
224
200
 
225
- Exit codes follow bash conventions: 0 ok, 1 fail, 2 usage/serious, 127 command not found,
226
- 124 timeout.
201
+ Unknown commands (git, node, npm, python, cargo, gh, docker, ...) are **passed through natively**
202
+ with argv-style quoting. Windows `.cmd`/`.bat` shims necessarily pass through `cmd.exe`; fauxnix
203
+ preserves its supported punctuation and fails loudly for `%`, embedded double quotes, NUL, and
204
+ line breaks rather than passing a different argument.
227
205
 
228
206
  ## How it works
229
207
 
@@ -237,14 +215,18 @@ agent ◀── GNU-style output, bash-style errors ◀── UTF-8 framed host
237
215
  - Each command maps to a generator that emits a self-contained PowerShell block honoring the
238
216
  "Fauxnix contract": string-per-line stdout, `[Console]::Error.WriteLine` for bash-style
239
217
  stderr, `$script:fx_exit` for exit codes, `$input` for stdin.
240
- - The executor wraps every script with UTF-8 enforcement (`[Console]::OutputEncoding`,
241
- `$OutputEncoding`, `chcp 65001`), decodes native output at the process boundary (UTF-8 by
242
- default or GBK(936) in `ansi` mode), keeps host frames UTF-8, strips CLIXML serialization and
218
+ - The executor wraps every script with UTF-8 enforcement, decodes native output at the process
219
+ boundary (UTF-8 by default or GBK(936) in `ansi` mode), strips CLIXML serialization and
243
220
  PowerShell noise from stderr, and rewrites common PowerShell errors (including zh-CN locale
244
- messages) into bash phrasing.
221
+ messages) into bash phrasing. File reads are always sniffed per file (UTF-8 strict → GBK
222
+ fallback), so grep/sed/awk over GBK files works in either mode.
245
223
  - Scripts run via `-EncodedCommand` (UTF-16LE) and transparently fall back to a temp `.ps1` file
246
224
  when the 32 KB command-line limit would be exceeded.
247
225
 
226
+ PowerShell 7 is an opt-in, CI-tested tier: set `FAUXNIX_PS=pwsh` before starting fauxnix or its
227
+ MCP harness. The default is Windows PowerShell 5.1; invalid values fail loudly rather than
228
+ falling back. See [PowerShell 7 support](docs/powershell-7.md).
229
+
248
230
  ## Known deviations (honest list)
249
231
 
250
232
  fauxnix optimizes for the commands agents actually run. Documented deviations:
@@ -255,17 +237,13 @@ fauxnix optimizes for the commands agents actually run. Documented deviations:
255
237
  word expansion precedes the temporary environment).
256
238
  - `yes` is capped at 65,536 lines — PS 5.1 pipelines cannot signal upstream producers to stop, so
257
239
  an unbounded `yes | head` would hang.
258
- - `tail -f`, `eval`, `alias`, heredocs,
259
- `env -i`/`--ignore-environment`,
260
- background `&`, and output/fd redirects (`>` `>>` `2>` `2>>` `&>` `&>>`
261
- `2>&1` `1>&2`) on a non-last pipeline stage (`echo hi >f | cat`) are
262
- rejected with operation-specific, actionable error messages instead of
263
- misbehaving. Per-stage `<` remains supported; fully routed per-stage output
264
- fds are still tracked by #157.
265
- (`if/then/elif/else/fi`, `for x in ...`, `while`/`until`, `case ... esac` (`;;` only; `;&`/`;;&` fail loud),
266
- backtick substitution, `command -v`, pipeline `read`,
267
- dotenv-style `source`, word-level `$((...))` arithmetic expansion, `A=(x y z)` arrays, and
268
- `${name//pat/str}` / `${name:off:len}` are supported.)
240
+ - `tail -f`, `eval`, `alias`, heredocs, `env -i`/`--ignore-environment`, background `&`, and
241
+ output/fd redirects on a non-last pipeline stage are rejected with operation-specific,
242
+ actionable error messages instead of misbehaving. Per-stage `<` remains supported.
243
+ (`if/then/elif/else/fi`, `for x in ...`, `while`/`until`, `case ... esac` (`;;` only),
244
+ backtick substitution, `command -v`, pipeline `read`, dotenv-style `source`, word-level
245
+ `$((...))` arithmetic expansion, `A=(x y z)` arrays, and `${name//pat/str}` /
246
+ `${name:off:len}` are supported.)
269
247
  - `command -v <builtin>` prints `/usr/bin/<name>` where bash prints the bare builtin name;
270
248
  exit codes and empty-result semantics match.
271
249
  - `chmod` maps only the read-only bit; exec bits are no-ops on Windows. `chown` is a silent no-op
@@ -278,13 +256,11 @@ fauxnix optimizes for the commands agents actually run. Documented deviations:
278
256
  "not supported" errors at translate time.
279
257
  - `curl`/`wget` refuse loopback/private/reserved addresses (localhost, 127.x, ::1, 10.x,
280
258
  172.16–31.x, 192.168.x, 169.254.x) as a safety default for agent-driven HTTP.
281
- - **Native-tool pipelines vs encoding**: PS 5.1 has a single console-encoding knob, so
282
- piping localized admin tools (ipconfig, tasklist — GBK on zh-CN) and UTF-8-native dev
283
- tools (node, curl) cannot both decode cleanly mid-pipeline. Default favors UTF-8 dev
284
- tools; set `FAUXNIX_NATIVE_ENCODING=ansi` when your agents grep Chinese output of
285
- native Windows admin tools. **File reads are always sniffed per file** (UTF-8 strict →
286
- GBK fallback), so grep/sed/awk over GBK *files* works in either mode — unlike Git Bash,
287
- which only matches the encoding its locale assumes.
259
+ - **Native-tool pipelines vs encoding**: PS 5.1 has a single console-encoding knob, so piping
260
+ localized admin tools (ipconfig, tasklist — GBK on zh-CN) and UTF-8-native dev tools (node,
261
+ curl) cannot both decode cleanly mid-pipeline. Default favors UTF-8 dev tools; set
262
+ `FAUXNIX_NATIVE_ENCODING=ansi` when your agents grep Chinese output of native Windows admin
263
+ tools.
288
264
 
289
265
  ## Development
290
266
 
@@ -296,14 +272,17 @@ npm run build
296
272
  npx tsx scratch/run.mjs "any bash command" # quick live check
297
273
  ```
298
274
 
299
- Differential vs Git Bash is opt-in (`FAUXNIX_DIFF_ORACLE=1`; skips if unset or `bash.exe` is missing — Git Bash is not required). See [`test/differential/README.md`](test/differential/README.md). The 253-case corpus enforces the RFC C-7 minimum of 200 cases and a 95% identity gate. The weekly oracle runs from `.github/workflows/differential.yml`; two consecutive green **scheduled** runs are still required release evidence after this gate lands.
275
+ Differential vs Git Bash is opt-in (`FAUXNIX_DIFF_ORACLE=1`; skips if unset or `bash.exe` is
276
+ missing — Git Bash is not required). See [`test/differential/README.md`](test/differential/README.md).
277
+ The 253-case corpus enforces the RFC C-7 minimum of 200 cases and a 95% identity gate; the weekly
278
+ oracle runs from `.github/workflows/differential.yml`.
300
279
 
301
280
  Architecture map: `src/parser.ts` (bash subset → AST) · `src/translator.ts` (AST → PowerShell +
302
281
  executor wrapper) · `src/executor.ts` (spawn, redirects, session persistence) ·
303
282
  `src/commands/*.ts` (per-command generators) · `src/mcp.ts` (MCP server) · `src/cli.ts`.
304
283
 
305
- Roadmap: [docs/rfc-roadmap-to-1.0.md](docs/rfc-roadmap-to-1.0.md) — tracks, milestones,
306
- and the RFC process for proposing waves.
284
+ Roadmap: [docs/rfc-roadmap-to-1.0.md](docs/rfc-roadmap-to-1.0.md) — tracks, milestones, and the
285
+ RFC process for proposing waves.
307
286
 
308
287
  ## Security
309
288
 
@@ -80,7 +80,7 @@ const ls = (args) => {
80
80
  " return ($t + 'rw-r--r--')",
81
81
  '}',
82
82
  'function fx-name($it) {',
83
- ' $n = $it.Name',
83
+ ' $n = $it.Name; if ($fx_operandMode -and $it.FauxnixOperand) { $n = $it.FauxnixOperand }',
84
84
  ' if (' + (classify ? '$true' : '$false') + ') {',
85
85
  " if ($it.PSIsContainer) { $n = $n + '/' } elseif (@('.exe','.bat','.cmd','.com','.msi','.ps1') -contains $it.Extension.ToLower()) { $n = $n + '*' } elseif " +
86
86
  psIsLink('$it') +
@@ -90,23 +90,19 @@ const ls = (args) => {
90
90
  '}',
91
91
  '$fx_targets = ' + targets,
92
92
  '$fx_all = @()',
93
+ '$fx_operandCount = 0',
93
94
  'foreach ($fx_t in $fx_targets) {',
94
95
  ' foreach ($fx_g in (fx-glob $fx_t)) {',
96
+ ' $fx_operandCount++',
95
97
  ' if (-not (Test-Path -LiteralPath $fx_g)) {',
96
98
  ' [Console]::Error.WriteLine("ls: cannot access \'" + $fx_t + "\': No such file or directory"); $script:fx_exit = 2; continue',
97
99
  ' }',
98
- ' $fx_all += ,(Get-Item -LiteralPath $fx_g -Force)',
99
- ' }',
100
- '}',
101
- '$fx_show = @()',
102
- 'if (' + (dirOnly ? '$true' : '$false') + ') { $fx_show = $fx_all }',
103
- 'else {',
104
- ' foreach ($fx_it in $fx_all) {',
105
- ' if ($fx_it.PSIsContainer) {',
106
- ' $fx_show += @(Get-ChildItem -LiteralPath $fx_it.FullName -Force:' + (all || almost ? '$true' : '$false') + ')',
107
- ' } else { $fx_show += ,$fx_it }',
100
+ ' $fx_entry = Get-Item -LiteralPath $fx_g -Force',
101
+ ' $fx_entry | Add-Member -NotePropertyName FauxnixOperand -NotePropertyValue ([string]$fx_g) -Force',
102
+ ' $fx_all += ,$fx_entry',
108
103
  ' }',
109
104
  '}',
105
+ 'function fx-render-ls-group($fx_show, $fx_operandMode) {',
110
106
  'if (' + (sortByTime ? '$true' : '$false') + ') { $fx_show = @($fx_show | Sort-Object -Property LastWriteTime -Descending) }',
111
107
  'elseif (' + (sortBySize ? '$true' : '$false') + ') { $fx_show = @($fx_show | Sort-Object -Property Length -Descending) }',
112
108
  'else { $fx_show = @($fx_show | Sort-Object -Property Name) }',
@@ -121,6 +117,24 @@ const ls = (args) => {
121
117
  ' fx-name $fx_it',
122
118
  ' }',
123
119
  '}',
120
+ '}',
121
+ 'if (' + (dirOnly ? '$true' : '$false') + ') { fx-render-ls-group $fx_all $true }',
122
+ 'else {',
123
+ ' $fx_files = @($fx_all | Where-Object { -not $_.PSIsContainer })',
124
+ ' if ($fx_files.Count -gt 0) { fx-render-ls-group $fx_files $true }',
125
+ ' $fx_directories = @($fx_all | Where-Object { $_.PSIsContainer } | Sort-Object -Property FauxnixOperand)',
126
+ ...(reverse ? [' [array]::Reverse($fx_directories)'] : []),
127
+ ' $fx_needSeparator = $fx_files.Count -gt 0',
128
+ ' foreach ($fx_directory in $fx_directories) {',
129
+ ' if ($fx_operandCount -gt 1) {',
130
+ " if ($fx_needSeparator) { '' }",
131
+ " ([string]$fx_directory.FauxnixOperand) + ':'",
132
+ ' }',
133
+ ' $fx_children = @(Get-ChildItem -LiteralPath $fx_directory.FullName -Force:' + (all || almost ? '$true' : '$false') + ')',
134
+ ' fx-render-ls-group $fx_children $false',
135
+ ' $fx_needSeparator = $true',
136
+ ' }',
137
+ '}',
124
138
  ].join('\n');
125
139
  };
126
140
  /* ------------------------------------------------------------------ */
@@ -151,7 +151,8 @@ const cd = (args) => {
151
151
  if (wordToString(operandWords[0]) === '-') {
152
152
  return [
153
153
  "if (-not $env:FAUXNIX_OLDPWD) { [Console]::Error.WriteLine('bash: cd: OLDPWD not set'); $script:fx_exit = 1 }",
154
- 'else { try { Set-Location -LiteralPath $env:FAUXNIX_OLDPWD } catch { [Console]::Error.WriteLine("bash: cd: " + $env:FAUXNIX_OLDPWD + ": No such file or directory"); $script:fx_exit = 1 } }',
154
+ // bash echoes the new cwd for `cd -` (and CDPATH hits); $OLDPWD/$PWD agree (#223).
155
+ 'else { try { Set-Location -LiteralPath $env:FAUXNIX_OLDPWD; fx-posix((Get-Location).Path) } catch { [Console]::Error.WriteLine("bash: cd: " + $env:FAUXNIX_OLDPWD + ": No such file or directory"); $script:fx_exit = 1 } }',
155
156
  ].join('\n');
156
157
  }
157
158
  return [
@@ -168,7 +169,8 @@ const pwd = (args) => {
168
169
  if (operandWords.length > 0)
169
170
  return psErr('pwd', "extra operand '" + wordToString(operandWords[0]) + "'. Try 'pwd --help'.");
170
171
  // -L is the default. CommandSpec rejects -P because junctions make it distinct.
171
- return "(Get-Location).Path.Replace('\\', '/')";
172
+ // bash renders the cwd POSIX-form (/d/foo); $PWD and `cd -` must agree (#223).
173
+ return 'fx-posix((Get-Location).Path)';
172
174
  };
173
175
  /* ------------------------------------------------------------------ */
174
176
  /* export / unset / env / printenv */
@@ -1537,12 +1539,12 @@ const FX_ENVGET_FN = [
1537
1539
  " if (@($env:FAUXNIX_UNSETVARS -split ';' | Where-Object { $_ -ceq $n }).Count -gt 0) { return '' }",
1538
1540
  " if (@($env:FAUXNIX_SETVARS -split ';' | Where-Object { $_ -ceq $n }).Count -gt 0) { return (fx-envexplicit $n) }",
1539
1541
  " if ($n -ceq 'HOME') { return [string]$HOME }",
1540
- " if ($n -ceq 'PWD') { return [string]$PWD.Path }",
1542
+ " if ($n -ceq 'PWD') { return fx-posix([string]$PWD.Path) }",
1541
1543
  " if ($n -ceq 'USER' -or $n -ceq 'LOGNAME') { return [string]$env:USERNAME }",
1542
1544
  " if ($n -ceq 'PATH') { return [string]$env:PATH }",
1543
1545
  " if ($n -ceq 'SHELL') { return 'powershell' }",
1544
1546
  " if ($n -ceq 'TERM') { return 'xterm-256color' }",
1545
- " if ($n -ceq 'OLDPWD') { return [string]$env:FAUXNIX_OLDPWD }",
1547
+ " if ($n -ceq 'OLDPWD') { return fx-posix([string]$env:FAUXNIX_OLDPWD) }",
1546
1548
  " if ($n -ceq '?') { return [string]$fx_prev }",
1547
1549
  " if ($n -ceq '$') { return [string]$PID }",
1548
1550
  " if ($n -ceq 'HOSTNAME') { return [string]$env:COMPUTERNAME }",
@@ -2427,9 +2429,9 @@ const DIRS_STACK_PS = [
2427
2429
  "if ($env:FAUXNIX_DIRSTACK) { $fx_st = @($env:FAUXNIX_DIRSTACK -split ';' | Where-Object { $_ -ne '' }) }",
2428
2430
  ].join('\n');
2429
2431
  const DIRS_PRINT_PS = [
2430
- '$fx_l = @((Get-Location).Path)',
2431
- 'foreach ($fx_s in $fx_st) { $fx_l += $fx_s }',
2432
- "($fx_l -join ' ').Replace('\\', '/')",
2432
+ '$fx_l = @(fx-posix((Get-Location).Path))',
2433
+ 'foreach ($fx_s in $fx_st) { $fx_l += fx-posix($fx_s) }',
2434
+ "($fx_l -join ' ')",
2433
2435
  ].join('\n');
2434
2436
  const dirs = () => {
2435
2437
  return [DIRS_STACK_PS, DIRS_PRINT_PS].join('\n');
@@ -1356,6 +1356,14 @@ class AwkParser {
1356
1356
  if (c === '{') {
1357
1357
  throw new FauxnixParseError('fauxnix: awk nested blocks are not supported yet');
1358
1358
  }
1359
+ if (c === '$') {
1360
+ const assignment = this.s.slice(this.i).match(/^\$([1-9]\d*)\s*=(?!=)/);
1361
+ if (!assignment || Number(assignment[1]) > 65535) {
1362
+ throw new FauxnixParseError('fauxnix: awk field assignment requires $1..$65535 = expression; use print to construct other records');
1363
+ }
1364
+ this.i += assignment[0].length;
1365
+ return { k: 'fieldassign', index: Number(assignment[1]), e: this.parseExpr() };
1366
+ }
1359
1367
  if (this.atWord('print')) {
1360
1368
  this.i += 5;
1361
1369
  this.ws();
@@ -1955,7 +1963,7 @@ const awk = (args) => {
1955
1963
  out.push('$fx_line');
1956
1964
  }
1957
1965
  else {
1958
- out.push('(' + st.args.map((a) => '(fx-str ' + gen(a).ps + ')').join(" + ' ' + ") + ')');
1966
+ out.push('(' + st.args.map((a) => '(fx-str ' + gen(a).ps + ')').join(' + (fx-str $fxv_OFS) + ') + ')');
1959
1967
  }
1960
1968
  }
1961
1969
  else if (st.k === 'printf') {
@@ -1978,6 +1986,13 @@ const awk = (args) => {
1978
1986
  const argList = argExprs.length ? ' ' + argExprs.join(', ') : '';
1979
1987
  out.push('(' + f.ps + ' -f' + argList + ')');
1980
1988
  }
1989
+ else if (st.k === 'fieldassign') {
1990
+ out.push('$fx_fieldValue = (fx-str ' + gen(st.e).ps + ')');
1991
+ out.push('if ($fx_flds.Count -lt ' + st.index + ") { $fx_flds += @('') * (" + st.index + ' - $fx_flds.Count) }');
1992
+ out.push('$fx_flds[' + (st.index - 1) + '] = $fx_fieldValue');
1993
+ out.push('$fx_nf = $fx_flds.Count');
1994
+ out.push('$fx_line = ($fx_flds -join (fx-str $fxv_OFS))');
1995
+ }
1981
1996
  else if (st.k === 'assign') {
1982
1997
  const rhs = gen(st.e).ps;
1983
1998
  if (st.op === '=') {
@@ -2005,6 +2020,7 @@ const awk = (args) => {
2005
2020
  lines.push(...hoistedRegex);
2006
2021
  for (const v of prog.vars)
2007
2022
  lines.push('$fxv_' + v + ' = $null');
2023
+ lines.push("$fxv_OFS = ' '", "$fx_line = ''", '$fx_flds = @()', '$fx_nf = 0');
2008
2024
  for (const [n, v] of vvars) {
2009
2025
  lines.push('$fxv_' + n + ' = ' + (/^-?(\d+\.?\d*|\.\d+)$/.test(v) ? '[double]' + v : psStr(v)));
2010
2026
  }
package/dist/errors.js CHANGED
@@ -122,5 +122,11 @@ export function normalizeStderr(stderr) {
122
122
  }
123
123
  return line;
124
124
  });
125
- return out.join('\n').replace(/\n{3,}/g, '\n\n').trim();
125
+ // GNU stderr lines are newline-terminated; bash guarantees a separating
126
+ // newline when 2>&1 merges stderr into a following stdout chunk (#222).
127
+ // Leading blank lines are PS boot noise; collapse runs of blanks only.
128
+ const joined = out.join('\n').replace(/\n{3,}/g, '\n\n');
129
+ if (!joined.trim())
130
+ return '';
131
+ return joined.replace(/^\n+/, '').replace(/[\r\n]+$/, '\n');
126
132
  }
@@ -6,6 +6,11 @@ export interface ExecResult {
6
6
  timedOut: boolean;
7
7
  cancelled: boolean;
8
8
  truncated: boolean;
9
+ /** True when caller-visible stdout crossed its byte budget. */
10
+ stdoutTruncated?: boolean;
11
+ /** True when caller-visible stderr crossed its byte budget. */
12
+ stderrTruncated?: boolean;
13
+ infrastructureError?: boolean;
9
14
  spawnError?: 'ENOENT' | 'START';
10
15
  }
11
16
  export interface ExecOptions {
@@ -16,6 +21,14 @@ export interface ExecOptions {
16
21
  stdoutLimit?: number;
17
22
  stderrLimit?: number;
18
23
  }
24
+ export type BatchStopReason = 'completed' | 'command_failed' | 'timed_out' | 'cancelled' | 'infrastructure';
25
+ export interface BatchExecOptions extends ExecOptions {
26
+ stopOnError?: boolean;
27
+ }
28
+ export interface BatchExecResult {
29
+ results: ExecResult[];
30
+ stopReason: BatchStopReason;
31
+ }
19
32
  /** Session persists cwd and env across segments, like a real shell. */
20
33
  export declare class FauxnixSession {
21
34
  id: string;
@@ -46,4 +59,10 @@ export declare class FauxnixSession {
46
59
  /** env for the child powershell process. */
47
60
  childEnv(cwdOverride?: string, stdinFile?: string | null): NodeJS.ProcessEnv;
48
61
  run(plans: SegmentPlan[], opts?: ExecOptions): Promise<ExecResult>;
62
+ /**
63
+ * Execute precompiled steps atomically in one session turn. Each step keeps
64
+ * its own result, while timeout and caller-output budgets cover the complete
65
+ * batch. No run/reset/dispose request can interleave between steps.
66
+ */
67
+ runBatch(planGroups: SegmentPlan[][], opts?: BatchExecOptions): Promise<BatchExecResult>;
49
68
  }