fauxnix-cli 0.12.0 → 0.13.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 +131 -152
- package/dist/commands/files.js +25 -11
- package/dist/commands/text-filters.js +17 -1
- package/dist/executor.d.ts +19 -0
- package/dist/executor.js +70 -0
- package/dist/mcp.d.ts +65 -1
- package/dist/mcp.js +183 -0
- package/dist/ps-host.d.ts +1 -0
- package/dist/ps-host.js +19 -19
- package/dist/translator.js +72 -7
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[](https://glama.ai/mcp/servers/20000419/fauxnix)
|
|
8
8
|
|
|
9
|
-
**Run Linux-style commands on Windows — natively, deterministically,
|
|
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
|
-
|
|
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
|

|
|
@@ -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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
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
|
-
|
|
155
|
-
|
|
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** —
|
|
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
|
-
|
|
182
|
-
|
|
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`).
|
|
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
|
|
192
|
-
|
|
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
|
-
|
|
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)
|
|
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
|
-
|
|
226
|
-
|
|
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
|
|
241
|
-
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
`
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
package/dist/commands/files.js
CHANGED
|
@@ -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
|
-
' $
|
|
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
|
/* ------------------------------------------------------------------ */
|
|
@@ -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/executor.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/executor.js
CHANGED
|
@@ -350,6 +350,65 @@ export class FauxnixSession {
|
|
|
350
350
|
run(plans, opts = {}) {
|
|
351
351
|
return this.withLock(() => runPlans(plans, this, opts, () => this.syncFromDisk(), () => this.ensureHost()));
|
|
352
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Execute precompiled steps atomically in one session turn. Each step keeps
|
|
355
|
+
* its own result, while timeout and caller-output budgets cover the complete
|
|
356
|
+
* batch. No run/reset/dispose request can interleave between steps.
|
|
357
|
+
*/
|
|
358
|
+
runBatch(planGroups, opts = {}) {
|
|
359
|
+
return this.withLock(async () => {
|
|
360
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
361
|
+
const deadline = Date.now() + timeoutMs;
|
|
362
|
+
let stdoutRemaining = validateOutputLimit('stdoutLimit', opts.stdoutLimit ?? DEFAULT_STDOUT_LIMIT);
|
|
363
|
+
let stderrRemaining = validateOutputLimit('stderrLimit', opts.stderrLimit ?? DEFAULT_STDERR_LIMIT);
|
|
364
|
+
const results = [];
|
|
365
|
+
let stopReason = 'completed';
|
|
366
|
+
for (const plans of planGroups) {
|
|
367
|
+
let result;
|
|
368
|
+
try {
|
|
369
|
+
result = await runPlans(plans, this, {
|
|
370
|
+
...opts,
|
|
371
|
+
timeoutMs: Math.max(0, deadline - Date.now()),
|
|
372
|
+
stdoutLimit: stdoutRemaining,
|
|
373
|
+
stderrLimit: stderrRemaining,
|
|
374
|
+
}, () => this.syncFromDisk(), () => this.ensureHost());
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
378
|
+
const clipped = clipUtf8(message, stderrRemaining);
|
|
379
|
+
result = {
|
|
380
|
+
stdout: '', stderr: clipped.text, exitCode: 1,
|
|
381
|
+
timedOut: false, cancelled: false, truncated: clipped.truncated,
|
|
382
|
+
infrastructureError: true,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
results.push(result);
|
|
386
|
+
stdoutRemaining = Math.max(0, stdoutRemaining - Buffer.byteLength(result.stdout, 'utf8'));
|
|
387
|
+
stderrRemaining = Math.max(0, stderrRemaining - Buffer.byteLength(result.stderr, 'utf8'));
|
|
388
|
+
if (result.stdoutTruncated)
|
|
389
|
+
stdoutRemaining = 0;
|
|
390
|
+
if (result.stderrTruncated)
|
|
391
|
+
stderrRemaining = 0;
|
|
392
|
+
if (result.cancelled) {
|
|
393
|
+
stopReason = 'cancelled';
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
if (result.timedOut) {
|
|
397
|
+
stopReason = 'timed_out';
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
if (result.spawnError || result.infrastructureError) {
|
|
401
|
+
stopReason = 'infrastructure';
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
if ((opts.stopOnError ?? true) && result.exitCode !== 0) {
|
|
405
|
+
stopReason = 'command_failed';
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return { results, stopReason };
|
|
410
|
+
});
|
|
411
|
+
}
|
|
353
412
|
}
|
|
354
413
|
async function runPlans(plans, session, opts, afterSegment, ensureHost) {
|
|
355
414
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
@@ -368,6 +427,7 @@ async function runPlans(plans, session, opts, afterSegment, ensureHost) {
|
|
|
368
427
|
let cancelled = false;
|
|
369
428
|
let truncated = false;
|
|
370
429
|
let spawnError;
|
|
430
|
+
let infrastructureError = false;
|
|
371
431
|
const appendCaller = (fd, data) => {
|
|
372
432
|
if (!data)
|
|
373
433
|
return;
|
|
@@ -540,6 +600,13 @@ async function runPlans(plans, session, opts, afterSegment, ensureHost) {
|
|
|
540
600
|
stdoutMode: hostStdout.mode,
|
|
541
601
|
stderrMode: hostStderr.mode,
|
|
542
602
|
});
|
|
603
|
+
if (inv.infrastructureError) {
|
|
604
|
+
appendCaller(2, inv.stderr.toString('utf8'));
|
|
605
|
+
exitCode = inv.exitCode;
|
|
606
|
+
session.prevExit = exitCode;
|
|
607
|
+
infrastructureError = true;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
543
610
|
if (inv.spawnError === 'ENOENT' || inv.spawnError === 'START') {
|
|
544
611
|
appendCaller(2, inv.stderr.toString('utf8') || 'fauxnix: failed to start the selected PowerShell host\n');
|
|
545
612
|
exitCode = 127;
|
|
@@ -654,6 +721,9 @@ async function runPlans(plans, session, opts, afterSegment, ensureHost) {
|
|
|
654
721
|
timedOut,
|
|
655
722
|
cancelled,
|
|
656
723
|
truncated,
|
|
724
|
+
stdoutTruncated: stdoutClosed,
|
|
725
|
+
stderrTruncated: stderrClosed,
|
|
726
|
+
infrastructureError,
|
|
657
727
|
spawnError,
|
|
658
728
|
};
|
|
659
729
|
}
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
|
-
import { ExecResult } from './executor.js';
|
|
1
|
+
import { BatchExecResult, ExecResult } from './executor.js';
|
|
2
2
|
import { translatePipelineBody } from './translator.js';
|
|
3
3
|
import './commands/install-all.js';
|
|
4
|
+
export interface BatchStepInput {
|
|
5
|
+
id?: string;
|
|
6
|
+
command: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class BatchCompileError extends Error {
|
|
9
|
+
readonly stepIndex: number;
|
|
10
|
+
readonly stepId: string | undefined;
|
|
11
|
+
constructor(stepIndex: number, stepId: string | undefined, cause: unknown);
|
|
12
|
+
}
|
|
13
|
+
export declare function compileBatchSteps(steps: BatchStepInput[]): import("./translator.js").SegmentPlan[][];
|
|
14
|
+
export declare function batchToolResult(inputs: BatchStepInput[], batch: BatchExecResult, sessionId: string): {
|
|
15
|
+
isError?: true | undefined;
|
|
16
|
+
content: {
|
|
17
|
+
type: "text";
|
|
18
|
+
text: string;
|
|
19
|
+
}[];
|
|
20
|
+
structuredContent: {
|
|
21
|
+
schemaVersion: 1;
|
|
22
|
+
sessionId: string;
|
|
23
|
+
preflightOk: boolean;
|
|
24
|
+
stopReason: import("./executor.js").BatchStopReason;
|
|
25
|
+
stepsRequested: number;
|
|
26
|
+
stepsCompleted: number;
|
|
27
|
+
timedOut: boolean;
|
|
28
|
+
cancelled: boolean;
|
|
29
|
+
truncated: boolean;
|
|
30
|
+
steps: ({
|
|
31
|
+
status: "skipped";
|
|
32
|
+
id?: string | undefined;
|
|
33
|
+
index: number;
|
|
34
|
+
} | {
|
|
35
|
+
status: "cancelled" | "completed" | "timed_out" | "failed" | "infrastructure_error";
|
|
36
|
+
stdout: string;
|
|
37
|
+
stderr: string;
|
|
38
|
+
exitCode: number;
|
|
39
|
+
timedOut: boolean;
|
|
40
|
+
cancelled: boolean;
|
|
41
|
+
truncated: boolean;
|
|
42
|
+
id?: string | undefined;
|
|
43
|
+
index: number;
|
|
44
|
+
})[];
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export declare function batchCompileErrorResult(inputs: BatchStepInput[], error: BatchCompileError, sessionId: string): {
|
|
48
|
+
content: {
|
|
49
|
+
type: "text";
|
|
50
|
+
text: string;
|
|
51
|
+
}[];
|
|
52
|
+
structuredContent: {
|
|
53
|
+
schemaVersion: 1;
|
|
54
|
+
sessionId: string;
|
|
55
|
+
preflightOk: boolean;
|
|
56
|
+
stopReason: "compile_error";
|
|
57
|
+
stepsRequested: number;
|
|
58
|
+
stepsCompleted: number;
|
|
59
|
+
failedStep: number;
|
|
60
|
+
steps: {
|
|
61
|
+
status: "skipped" | "compile_error";
|
|
62
|
+
id?: string | undefined;
|
|
63
|
+
index: number;
|
|
64
|
+
}[];
|
|
65
|
+
};
|
|
66
|
+
isError: true;
|
|
67
|
+
};
|
|
4
68
|
export declare function formatBashText(r: Pick<ExecResult, 'stdout' | 'stderr' | 'exitCode' | 'timedOut' | 'cancelled'>): string;
|
|
5
69
|
export declare function bashToolResult(r: ExecResult, sessionId: string, infra: boolean): {
|
|
6
70
|
isError?: true | undefined;
|
package/dist/mcp.js
CHANGED
|
@@ -8,6 +8,11 @@ import { registeredNames } from './registry.js';
|
|
|
8
8
|
import { packageVersion } from './version.js';
|
|
9
9
|
import './commands/install-all.js';
|
|
10
10
|
const TOOL_NAME = process.env.FAUXNIX_TOOL_NAME || 'bash';
|
|
11
|
+
const BATCH_TOOL_NAME = TOOL_NAME + '_batch';
|
|
12
|
+
// Text and structured output both appear in the JSON response. Leave room for
|
|
13
|
+
// worst-case JSON escaping below the official stdio client's 10 MiB limit.
|
|
14
|
+
const BATCH_STDOUT_LIMIT = 262_144;
|
|
15
|
+
const BATCH_STDERR_LIMIT = 65_536;
|
|
11
16
|
const EXEC_ANNOTATIONS = {
|
|
12
17
|
readOnlyHint: false,
|
|
13
18
|
destructiveHint: true,
|
|
@@ -35,9 +40,113 @@ Supported: pipes (|), && / || / ;, redirections (> >> 2> 2>&1 < /dev/null), vari
|
|
|
35
40
|
Unknown commands (git, node, npm, python, cargo...) are passed through and executed natively with argv-style quoting.
|
|
36
41
|
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.
|
|
37
42
|
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.
|
|
43
|
+
Efficiency: when two or more commands or verification steps are already known, prefer ${BATCH_TOOL_NAME} once instead of making several ${TOOL_NAME} 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.
|
|
38
44
|
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.
|
|
39
45
|
|
|
40
46
|
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.`;
|
|
47
|
+
const BATCH_TOOL_DESCRIPTION = `Compile and execute a preplanned multi-step bash workflow in one MCP round trip.
|
|
48
|
+
|
|
49
|
+
Use this instead of repeated ${TOOL_NAME} 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.
|
|
50
|
+
|
|
51
|
+
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 ${TOOL_NAME} calls instead. For byte counts, include wc -c or stat -c %s as a verification step rather than calculating CRLF bytes mentally.`;
|
|
52
|
+
export class BatchCompileError extends Error {
|
|
53
|
+
stepIndex;
|
|
54
|
+
stepId;
|
|
55
|
+
constructor(stepIndex, stepId, cause) {
|
|
56
|
+
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
57
|
+
super('fauxnix: batch compile failed at step ' +
|
|
58
|
+
String(stepIndex + 1) +
|
|
59
|
+
(stepId ? ' (' + stepId + ')' : '') +
|
|
60
|
+
': ' +
|
|
61
|
+
detail);
|
|
62
|
+
this.stepIndex = stepIndex;
|
|
63
|
+
this.stepId = stepId;
|
|
64
|
+
this.name = 'BatchCompileError';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function compileBatchSteps(steps) {
|
|
68
|
+
return steps.map((step, index) => {
|
|
69
|
+
try {
|
|
70
|
+
return translateCommandList(parseCommand(step.command), PURE_TRANSLATION);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
throw new BatchCompileError(index, step.id, e);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function batchStepStatus(r) {
|
|
78
|
+
if (r.spawnError || r.infrastructureError)
|
|
79
|
+
return 'infrastructure_error';
|
|
80
|
+
if (r.cancelled)
|
|
81
|
+
return 'cancelled';
|
|
82
|
+
if (r.timedOut)
|
|
83
|
+
return 'timed_out';
|
|
84
|
+
return r.exitCode === 0 ? 'completed' : 'failed';
|
|
85
|
+
}
|
|
86
|
+
export function batchToolResult(inputs, batch, sessionId) {
|
|
87
|
+
const steps = inputs.map((input, index) => {
|
|
88
|
+
const result = batch.results[index];
|
|
89
|
+
if (!result)
|
|
90
|
+
return { index, ...(input.id ? { id: input.id } : {}), status: 'skipped' };
|
|
91
|
+
return {
|
|
92
|
+
index,
|
|
93
|
+
...(input.id ? { id: input.id } : {}),
|
|
94
|
+
status: batchStepStatus(result),
|
|
95
|
+
stdout: result.stdout,
|
|
96
|
+
stderr: result.stderr,
|
|
97
|
+
exitCode: result.exitCode,
|
|
98
|
+
timedOut: result.timedOut,
|
|
99
|
+
cancelled: result.cancelled,
|
|
100
|
+
truncated: result.truncated,
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
const text = steps
|
|
104
|
+
.map((step, index) => {
|
|
105
|
+
const label = '[' + String(index + 1) + '/' + String(steps.length) + (step.id ? ' ' + step.id : '') + ']';
|
|
106
|
+
if (step.status === 'skipped')
|
|
107
|
+
return label + ' skipped';
|
|
108
|
+
const result = batch.results[index];
|
|
109
|
+
return label + ' ' + step.status + ' (exit ' + String(result.exitCode) + ')\n' + formatBashText(result);
|
|
110
|
+
})
|
|
111
|
+
.join('\n');
|
|
112
|
+
const structuredContent = {
|
|
113
|
+
schemaVersion: 1,
|
|
114
|
+
sessionId,
|
|
115
|
+
preflightOk: true,
|
|
116
|
+
stopReason: batch.stopReason,
|
|
117
|
+
stepsRequested: inputs.length,
|
|
118
|
+
stepsCompleted: batch.results.length,
|
|
119
|
+
timedOut: batch.stopReason === 'timed_out',
|
|
120
|
+
cancelled: batch.stopReason === 'cancelled',
|
|
121
|
+
truncated: batch.results.some((result) => result.truncated),
|
|
122
|
+
steps,
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
content: [{ type: 'text', text }],
|
|
126
|
+
structuredContent,
|
|
127
|
+
...(batch.stopReason === 'infrastructure' ? { isError: true } : {}),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export function batchCompileErrorResult(inputs, error, sessionId) {
|
|
131
|
+
return {
|
|
132
|
+
content: [{ type: 'text', text: error.message }],
|
|
133
|
+
structuredContent: {
|
|
134
|
+
schemaVersion: 1,
|
|
135
|
+
sessionId,
|
|
136
|
+
preflightOk: false,
|
|
137
|
+
stopReason: 'compile_error',
|
|
138
|
+
stepsRequested: inputs.length,
|
|
139
|
+
stepsCompleted: 0,
|
|
140
|
+
failedStep: error.stepIndex,
|
|
141
|
+
steps: inputs.map((input, index) => ({
|
|
142
|
+
index,
|
|
143
|
+
...(input.id ? { id: input.id } : {}),
|
|
144
|
+
status: index === error.stepIndex ? 'compile_error' : 'skipped',
|
|
145
|
+
})),
|
|
146
|
+
},
|
|
147
|
+
isError: true,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
41
150
|
export function formatBashText(r) {
|
|
42
151
|
const parts = [];
|
|
43
152
|
if (r.stdout.length)
|
|
@@ -144,6 +253,80 @@ export async function startMcpServer() {
|
|
|
144
253
|
}, session.id, true);
|
|
145
254
|
}
|
|
146
255
|
});
|
|
256
|
+
server.tool(BATCH_TOOL_NAME, BATCH_TOOL_DESCRIPTION, {
|
|
257
|
+
steps: z
|
|
258
|
+
.array(z.object({
|
|
259
|
+
id: z.string().min(1).max(64).optional().describe('Optional short step label'),
|
|
260
|
+
command: z.string().min(1).max(16384).describe('Bash-style command for this step'),
|
|
261
|
+
}))
|
|
262
|
+
.min(1)
|
|
263
|
+
.max(32)
|
|
264
|
+
.describe('Ordered workflow steps; all are compiled before execution begins'),
|
|
265
|
+
stop_on_error: z
|
|
266
|
+
.boolean()
|
|
267
|
+
.optional()
|
|
268
|
+
.default(true)
|
|
269
|
+
.describe('Stop after the first nonzero exit (default true)'),
|
|
270
|
+
timeout_ms: z
|
|
271
|
+
.number()
|
|
272
|
+
.int()
|
|
273
|
+
.min(1000)
|
|
274
|
+
.max(600_000)
|
|
275
|
+
.optional()
|
|
276
|
+
.describe('Total timeout for the complete batch (default 120000)'),
|
|
277
|
+
stdout_limit_bytes: z
|
|
278
|
+
.number()
|
|
279
|
+
.int()
|
|
280
|
+
.min(0)
|
|
281
|
+
.max(BATCH_STDOUT_LIMIT)
|
|
282
|
+
.optional()
|
|
283
|
+
.describe('Total stdout budget shared by every step (default 262144)'),
|
|
284
|
+
stderr_limit_bytes: z
|
|
285
|
+
.number()
|
|
286
|
+
.int()
|
|
287
|
+
.min(0)
|
|
288
|
+
.max(BATCH_STDERR_LIMIT)
|
|
289
|
+
.optional()
|
|
290
|
+
.describe('Total stderr budget shared by every step (default 65536)'),
|
|
291
|
+
}, EXEC_ANNOTATIONS, async ({ steps, stop_on_error, timeout_ms, stdout_limit_bytes, stderr_limit_bytes }, extra) => {
|
|
292
|
+
try {
|
|
293
|
+
const compiled = compileBatchSteps(steps);
|
|
294
|
+
const result = await session.runBatch(compiled, {
|
|
295
|
+
stopOnError: stop_on_error,
|
|
296
|
+
timeoutMs: timeout_ms,
|
|
297
|
+
stdoutLimit: stdout_limit_bytes ?? BATCH_STDOUT_LIMIT,
|
|
298
|
+
stderrLimit: stderr_limit_bytes ?? BATCH_STDERR_LIMIT,
|
|
299
|
+
signal: extra.signal,
|
|
300
|
+
});
|
|
301
|
+
return batchToolResult(steps, result, session.id);
|
|
302
|
+
}
|
|
303
|
+
catch (e) {
|
|
304
|
+
if (e instanceof BatchCompileError) {
|
|
305
|
+
return batchCompileErrorResult(steps, e, session.id);
|
|
306
|
+
}
|
|
307
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
308
|
+
return {
|
|
309
|
+
content: [{ type: 'text', text: message }],
|
|
310
|
+
structuredContent: {
|
|
311
|
+
schemaVersion: 1,
|
|
312
|
+
sessionId: session.id,
|
|
313
|
+
preflightOk: true,
|
|
314
|
+
stopReason: 'infrastructure',
|
|
315
|
+
stepsRequested: steps.length,
|
|
316
|
+
stepsCompleted: 0,
|
|
317
|
+
timedOut: false,
|
|
318
|
+
cancelled: false,
|
|
319
|
+
truncated: false,
|
|
320
|
+
steps: steps.map((step, index) => ({
|
|
321
|
+
index,
|
|
322
|
+
...(step.id ? { id: step.id } : {}),
|
|
323
|
+
status: 'skipped',
|
|
324
|
+
})),
|
|
325
|
+
},
|
|
326
|
+
isError: true,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
});
|
|
147
330
|
server.tool('fauxnix_translate', 'Translate a bash-style command into the equivalent PowerShell script WITHOUT executing it. Useful for learning/debugging what fauxnix does under the hood.', { command: z.string().describe('The bash-style command line to translate (never executed)') }, TRANSLATE_ANNOTATIONS, async ({ command }) => translateToolResult(command));
|
|
148
331
|
server.tool('fauxnix_session', 'Inspect or reset the persistent fauxnix shell session (current directory, environment, positional count, session id). Actions: "status" (default) or "reset".', {
|
|
149
332
|
action: z
|
package/dist/ps-host.d.ts
CHANGED
package/dist/ps-host.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import { closeSync,
|
|
2
|
+
import { closeSync, openSync, readSync, rmSync, statSync, writeFileSync, writeSync, } from 'node:fs';
|
|
3
3
|
import { hostBootstrapScript } from './translator.js';
|
|
4
4
|
import { POWERSHELL_ARGS, powerShellMissingMessage, resolvePowerShell, } from './powershell.js';
|
|
5
5
|
class NativeStderrSpoolError extends Error {
|
|
@@ -160,7 +160,6 @@ export class PowerShellHost {
|
|
|
160
160
|
resolvedLimits.nativeStderrSpoolPath = this.hostFile + '.' + id + '.native-stderr';
|
|
161
161
|
}
|
|
162
162
|
const nativeSpoolDir = this.hostFile + '.' + id + '.native';
|
|
163
|
-
mkdirSync(nativeSpoolDir);
|
|
164
163
|
const requestEnv = { ...env, FAUXNIX_NATIVE_SPOOL_DIR: nativeSpoolDir };
|
|
165
164
|
const line = encodeHostRequest(id, script, requestEnv, this.protocol === 2
|
|
166
165
|
? {
|
|
@@ -182,6 +181,7 @@ export class PowerShellHost {
|
|
|
182
181
|
cancelled: false,
|
|
183
182
|
truncated: false,
|
|
184
183
|
spawnMessage: e.message,
|
|
184
|
+
infrastructureError: true,
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
187
|
let cancelled = false;
|
|
@@ -230,6 +230,7 @@ export class PowerShellHost {
|
|
|
230
230
|
return {
|
|
231
231
|
stdout: Buffer.alloc(0),
|
|
232
232
|
stderr: Buffer.from(nativeSpoolError.message + '\n', 'utf8'),
|
|
233
|
+
infrastructureError: true,
|
|
233
234
|
exitCode: 1,
|
|
234
235
|
timedOut: false,
|
|
235
236
|
cancelled: false,
|
|
@@ -254,6 +255,7 @@ export class PowerShellHost {
|
|
|
254
255
|
(code !== 1 ? ' (exit ' + String(code) + ')' : '') +
|
|
255
256
|
'\n', 'utf8'),
|
|
256
257
|
exitCode: code === 0 ? 1 : code,
|
|
258
|
+
infrastructureError: true,
|
|
257
259
|
timedOut: false,
|
|
258
260
|
cancelled: false,
|
|
259
261
|
truncated: false,
|
|
@@ -531,16 +533,13 @@ export class PowerShellHost {
|
|
|
531
533
|
let native = Buffer.alloc(0);
|
|
532
534
|
let nativeTruncated = false;
|
|
533
535
|
const nativeSpool = limits?.nativeStderrSpoolPath;
|
|
534
|
-
if ((limits?.stderrMode ?? 'capture') === 'capture' && nativeSpool) {
|
|
536
|
+
if ((limits?.stderrMode ?? 'capture') === 'capture' && nativeSpool && nativeBytes > 0) {
|
|
535
537
|
const remaining = Math.max(0, (limits?.stderrLimit ?? DEFAULT_STDERR_LIMIT) - capturedErr.length);
|
|
536
538
|
const clipped = this.readUtf8Prefix(nativeSpool, remaining, nativeBytes);
|
|
537
539
|
native = Buffer.from(clipped.data);
|
|
538
540
|
nativeTruncated = clipped.truncated;
|
|
539
541
|
rmSync(nativeSpool, { force: true });
|
|
540
542
|
}
|
|
541
|
-
if (limits?.stderrMode === 'spool' && nativeSpool && nativeBytes === 0) {
|
|
542
|
-
rmSync(nativeSpool, { force: true });
|
|
543
|
-
}
|
|
544
543
|
const n = Number(end.exitCode);
|
|
545
544
|
return {
|
|
546
545
|
stdout: Buffer.from(Buffer.concat(out)),
|
|
@@ -569,16 +568,6 @@ export class PowerShellHost {
|
|
|
569
568
|
this.nativeCapture = null;
|
|
570
569
|
reject(failure);
|
|
571
570
|
}, timeoutMs);
|
|
572
|
-
let spoolFd;
|
|
573
|
-
let ioError;
|
|
574
|
-
if (mode !== 'discard' && spoolPath) {
|
|
575
|
-
try {
|
|
576
|
-
spoolFd = openSync(spoolPath, 'w');
|
|
577
|
-
}
|
|
578
|
-
catch (e) {
|
|
579
|
-
ioError = new NativeStderrSpoolError('open', spoolPath, e);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
571
|
this.nativeCapture = {
|
|
583
572
|
id,
|
|
584
573
|
needle: Buffer.from('FAUXNIX_ERR_END:' + id + '\n', 'utf8'),
|
|
@@ -586,10 +575,8 @@ export class PowerShellHost {
|
|
|
586
575
|
limit: Math.max(0, limit),
|
|
587
576
|
tail: Buffer.alloc(0),
|
|
588
577
|
spoolPath,
|
|
589
|
-
spoolFd,
|
|
590
578
|
bytesWritten: 0,
|
|
591
579
|
bytesSeen: 0,
|
|
592
|
-
ioError,
|
|
593
580
|
resolve,
|
|
594
581
|
reject,
|
|
595
582
|
timer,
|
|
@@ -605,13 +592,26 @@ export class PowerShellHost {
|
|
|
605
592
|
if (!data.length)
|
|
606
593
|
return;
|
|
607
594
|
state.bytesSeen += data.length;
|
|
608
|
-
if (state.ioError || state.mode === 'discard'
|
|
595
|
+
if (state.ioError || state.mode === 'discard')
|
|
609
596
|
return;
|
|
610
597
|
let retained = data;
|
|
611
598
|
if (state.mode === 'capture') {
|
|
612
599
|
const remaining = Math.max(0, state.limit + 3 - state.bytesWritten);
|
|
613
600
|
retained = data.subarray(0, remaining);
|
|
614
601
|
}
|
|
602
|
+
if (!retained.length)
|
|
603
|
+
return;
|
|
604
|
+
if (state.spoolFd === undefined) {
|
|
605
|
+
if (!state.spoolPath)
|
|
606
|
+
return;
|
|
607
|
+
try {
|
|
608
|
+
state.spoolFd = openSync(state.spoolPath, 'w');
|
|
609
|
+
}
|
|
610
|
+
catch (e) {
|
|
611
|
+
state.ioError = new NativeStderrSpoolError('open', state.spoolPath, e);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
615
|
try {
|
|
616
616
|
let offset = 0;
|
|
617
617
|
while (offset < retained.length) {
|
package/dist/translator.js
CHANGED
|
@@ -1349,13 +1349,13 @@ function wrapCwdPreamble() {
|
|
|
1349
1349
|
'$script:fx_exit = 0',
|
|
1350
1350
|
'$fx_prev = 0',
|
|
1351
1351
|
'if ($env:FAUXNIX_PREV_EXIT) { try { $fx_prev = [int]$env:FAUXNIX_PREV_EXIT } catch { $fx_prev = 0 } }',
|
|
1352
|
-
'if ($env:FAUXNIX_CWD) { try { Set-Location -LiteralPath $env:FAUXNIX_CWD } catch {} }',
|
|
1352
|
+
'if ($env:FAUXNIX_CWD -and (Get-Location).ProviderPath -cne $env:FAUXNIX_CWD) { try { Set-Location -LiteralPath $env:FAUXNIX_CWD } catch {} }',
|
|
1353
1353
|
// capture AFTER the session cwd is applied — OLDPWD must refer to the
|
|
1354
1354
|
// shell's previous directory, not the host process' startup directory
|
|
1355
1355
|
'$fx_oldcwd = (Get-Location).ProviderPath',
|
|
1356
1356
|
// .NET APIs (ReadAllBytes & friends) resolve relative paths against the
|
|
1357
1357
|
// process working directory, NOT the PS location — keep them in sync.
|
|
1358
|
-
'try { [Environment]::CurrentDirectory
|
|
1358
|
+
'try { if ([Environment]::CurrentDirectory -cne $fx_oldcwd) { [Environment]::CurrentDirectory = $fx_oldcwd } } catch {}',
|
|
1359
1359
|
];
|
|
1360
1360
|
}
|
|
1361
1361
|
function wrapBodyAndPersist(body, exitProcess) {
|
|
@@ -1370,12 +1370,20 @@ function wrapBodyAndPersist(body, exitProcess) {
|
|
|
1370
1370
|
' $script:fx_exit = 1',
|
|
1371
1371
|
'}',
|
|
1372
1372
|
'# persist session cwd and environment for the next segment',
|
|
1373
|
-
|
|
1373
|
+
...(exitProcess ? [
|
|
1374
|
+
'try { [IO.File]::WriteAllText($env:FAUXNIX_CWD_FILE, (Get-Location).Path) } catch {}',
|
|
1375
|
+
] : [
|
|
1376
|
+
'try { [FauxnixSessionState]::SaveCwd($env:FAUXNIX_CWD_FILE, (Get-Location).Path) } catch {}',
|
|
1377
|
+
]),
|
|
1374
1378
|
'if ((Get-Location).Path -ne $fx_oldcwd) { $env:FAUXNIX_OLDPWD = $fx_oldcwd }',
|
|
1375
1379
|
'try {',
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1380
|
+
...(exitProcess ? [
|
|
1381
|
+
' $envObj = @{}',
|
|
1382
|
+
' Get-ChildItem Env: | ForEach-Object { $envObj[$_.Name] = $_.Value }',
|
|
1383
|
+
' [IO.File]::WriteAllText($env:FAUXNIX_ENV_FILE, (ConvertTo-Json $envObj -Compress))',
|
|
1384
|
+
] : [
|
|
1385
|
+
' [FauxnixSessionState]::SaveEnvironment($env:FAUXNIX_ENV_FILE)',
|
|
1386
|
+
]),
|
|
1379
1387
|
'} catch {}',
|
|
1380
1388
|
];
|
|
1381
1389
|
if (exitProcess)
|
|
@@ -1846,7 +1854,7 @@ export function wrapScript(body, opts = {}) {
|
|
|
1846
1854
|
' $fx_spoolUtf8 = New-Object System.Text.UTF8Encoding $false',
|
|
1847
1855
|
' try {',
|
|
1848
1856
|
' if (-not $term) {',
|
|
1849
|
-
" if ($env:FAUXNIX_NATIVE_SPOOL_DIR) { $fx_no = Join-Path $env:FAUXNIX_NATIVE_SPOOL_DIR (([guid]::NewGuid().ToString('N')) + '.out') }",
|
|
1857
|
+
" if ($env:FAUXNIX_NATIVE_SPOOL_DIR) { [void][IO.Directory]::CreateDirectory($env:FAUXNIX_NATIVE_SPOOL_DIR); $fx_no = Join-Path $env:FAUXNIX_NATIVE_SPOOL_DIR (([guid]::NewGuid().ToString('N')) + '.out') }",
|
|
1850
1858
|
' else { $fx_no = [IO.Path]::GetTempFileName() }',
|
|
1851
1859
|
' }',
|
|
1852
1860
|
' [void]$p.Start()',
|
|
@@ -1907,6 +1915,63 @@ if (-not ('FauxnixBoundedStream' -as [type])) {
|
|
|
1907
1915
|
Add-Type -TypeDefinition @'
|
|
1908
1916
|
using System;
|
|
1909
1917
|
using System.IO;
|
|
1918
|
+
using System.Collections;
|
|
1919
|
+
using System.Text;
|
|
1920
|
+
public static class FauxnixSessionState {
|
|
1921
|
+
private static string previousCwdPath;
|
|
1922
|
+
private static string previousCwd;
|
|
1923
|
+
private static string previousEnvironmentPath;
|
|
1924
|
+
private static string previousEnvironment;
|
|
1925
|
+
public static void SaveCwd(string path, string cwd) {
|
|
1926
|
+
if (path == previousCwdPath && cwd == previousCwd && File.Exists(path)) return;
|
|
1927
|
+
File.WriteAllText(path, cwd, new UTF8Encoding(false));
|
|
1928
|
+
previousCwdPath = path;
|
|
1929
|
+
previousCwd = cwd;
|
|
1930
|
+
}
|
|
1931
|
+
private static void AppendJsonString(StringBuilder json, string value) {
|
|
1932
|
+
json.Append((char)34);
|
|
1933
|
+
foreach (char c in value) {
|
|
1934
|
+
if (c == (char)34 || c == (char)92) {
|
|
1935
|
+
json.Append((char)92).Append(c);
|
|
1936
|
+
} else if (c < 32 || Char.IsSurrogate(c)) {
|
|
1937
|
+
json.Append((char)92).Append('u').Append(((int)c).ToString("x4"));
|
|
1938
|
+
} else {
|
|
1939
|
+
json.Append(c);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
json.Append((char)34);
|
|
1943
|
+
}
|
|
1944
|
+
public static void SaveEnvironment(string path) {
|
|
1945
|
+
// Keep a complete snapshot: merging with the parent's environment on a
|
|
1946
|
+
// later restart would resurrect values removed by unset.
|
|
1947
|
+
IDictionary environment = Environment.GetEnvironmentVariables();
|
|
1948
|
+
var json = new StringBuilder(4096);
|
|
1949
|
+
json.Append('{');
|
|
1950
|
+
bool first = true;
|
|
1951
|
+
var keys = new string[environment.Count];
|
|
1952
|
+
environment.Keys.CopyTo(keys, 0);
|
|
1953
|
+
Array.Sort(keys, StringComparer.Ordinal);
|
|
1954
|
+
foreach (string key in keys) {
|
|
1955
|
+
// These values are request transport metadata and are always supplied
|
|
1956
|
+
// afresh by Node; changing them does not change persistent shell state.
|
|
1957
|
+
if (String.Equals(key, "FAUXNIX_NATIVE_SPOOL_DIR", StringComparison.OrdinalIgnoreCase) ||
|
|
1958
|
+
String.Equals(key, "FAUXNIX_PREV_EXIT", StringComparison.OrdinalIgnoreCase) ||
|
|
1959
|
+
String.Equals(key, "FAUXNIX_STDIN_FILE", StringComparison.OrdinalIgnoreCase) ||
|
|
1960
|
+
String.Equals(key, "FAUXNIX_CWD", StringComparison.OrdinalIgnoreCase)) continue;
|
|
1961
|
+
if (!first) json.Append(',');
|
|
1962
|
+
first = false;
|
|
1963
|
+
AppendJsonString(json, key);
|
|
1964
|
+
json.Append(':');
|
|
1965
|
+
AppendJsonString(json, (string)environment[key]);
|
|
1966
|
+
}
|
|
1967
|
+
json.Append('}');
|
|
1968
|
+
string current = json.ToString();
|
|
1969
|
+
if (path == previousEnvironmentPath && current == previousEnvironment && File.Exists(path)) return;
|
|
1970
|
+
File.WriteAllText(path, current, new UTF8Encoding(false));
|
|
1971
|
+
previousEnvironmentPath = path;
|
|
1972
|
+
previousEnvironment = current;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1910
1975
|
public sealed class FauxnixBoundedStream : Stream {
|
|
1911
1976
|
private readonly MemoryStream inner;
|
|
1912
1977
|
private readonly long limit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fauxnix-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Fauxnix — run Linux-style commands on Windows via deterministic PowerShell translation. No VM, no WSL. MCP server + CLI for AI agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"release:check": "node scripts/release-check.mjs",
|
|
19
19
|
"test": "vitest run",
|
|
20
20
|
"test:package": "node scripts/package-smoke.mjs",
|
|
21
|
+
"benchmark:mcp-batch": "npm run build && node scripts/benchmark-mcp-batch.mjs",
|
|
21
22
|
"test:watch": "vitest",
|
|
22
23
|
"typecheck": "tsc --noEmit",
|
|
23
24
|
"dev": "tsx src/index.ts"
|