fauxnix-cli 0.2.1 → 0.3.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 +203 -199
- package/dist/ast.d.ts +7 -1
- package/dist/ast.js +10 -0
- package/dist/cli.js +13 -13
- package/dist/commands/sysinfo.js +1300 -48
- package/dist/encoding.d.ts +9 -0
- package/dist/encoding.js +19 -0
- package/dist/executor.js +230 -108
- package/dist/mcp.js +1 -1
- package/dist/parser.d.ts +2 -0
- package/dist/parser.js +420 -15
- package/dist/registry.js +10 -0
- package/dist/translator.d.ts +16 -1
- package/dist/translator.js +271 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,199 +1,203 @@
|
|
|
1
|
-
# fauxnix
|
|
2
|
-
|
|
3
|
-
**Run Linux-style commands on Windows — natively, deterministically, with no VM and no WSL.**
|
|
4
|
-
|
|
5
|
-
fauxnix is a bash→PowerShell translation layer built for AI agents. Your agent keeps writing the
|
|
6
|
-
bash it already knows (`ls -la | grep foo`, `find . -name '*.ts' | wc -l`, `kill -9 1234`), and
|
|
7
|
-
fauxnix deterministically translates each command into PowerShell, executes it natively, and hands
|
|
8
|
-
back output that looks like GNU/Linux: `ls -l` columns, bash-style error messages, coreutils exit
|
|
9
|
-
codes, UTF-8/GBK handled automatically.
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
$ fauxnix "ls -la src | head -2"
|
|
13
|
-
-rw-r--r-- 1 me me 1204 Aug 16 09:12 ast.ts
|
|
14
|
-
-rw-r--r-- 1 me me 8192 Aug 16 09:12 cli.ts
|
|
15
|
-
|
|
16
|
-
$ fauxnix "cat nope.txt"
|
|
17
|
-
cat: nope.txt: No such file or directory # not a PowerShell stack trace
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Why
|
|
21
|
-
|
|
22
|
-
LLM agents are dramatically better at bash than at PowerShell — bash dominates training data, so
|
|
23
|
-
models on Windows often produce "looks right, doesn't run" commands (wrong quoting, `curl` that
|
|
24
|
-
isn't curl, mojibake from codepage mismatches, inscrutable `CategoryInfo` error dumps). Existing
|
|
25
|
-
solutions are either a full VM (WSL — heavy, wrong filesystem, separate environment) or plain
|
|
26
|
-
shell wrappers (still PowerShell underneath).
|
|
27
|
-
|
|
28
|
-
fauxnix takes the third road: **translate, don't emulate**. A large, high-value subset of the
|
|
29
|
-
Linux command line — file ops, text processing, process management, archives, networking basics —
|
|
30
|
-
maps cleanly onto PowerShell + .NET. fauxnix implements that subset faithfully and *fails loudly
|
|
31
|
-
and helpfully* on what it can't translate, so the agent never gets silently-wrong results.
|
|
32
|
-
|
|
33
|
-
## Install
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
npm install -g fauxnix-cli
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Or from source:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
git clone https://github.com/20000419/fauxnix && cd fauxnix && npm install -g .
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
> npm package name is `fauxnix-cli` (the `fauxnix` name on npm belongs to an
|
|
46
|
-
> unrelated 2015 websocket library); the installed command is still `fauxnix`.
|
|
47
|
-
|
|
48
|
-
Requires: Windows with PowerShell 5.1+ (built-in) and Node.js ≥ 18.
|
|
49
|
-
|
|
50
|
-
## Quick start
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
# one-off commands
|
|
54
|
-
fauxnix "ls -la"
|
|
55
|
-
fauxnix "grep -rn TODO src | wc -l"
|
|
56
|
-
fauxnix "cat log.txt | grep -i error | sort | uniq -c"
|
|
57
|
-
|
|
58
|
-
# see what a command becomes (great for debugging / learning PS)
|
|
59
|
-
fauxnix translate "find . -name '*.log' -mtime +7 -delete"
|
|
60
|
-
|
|
61
|
-
# check your environment
|
|
62
|
-
fauxnix check
|
|
63
|
-
|
|
64
|
-
# run the MCP stdio server (what agent harnesses connect to)
|
|
65
|
-
fauxnix mcp
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Unknown commands (git, node, npm, python, cargo, gh, docker, ...) are **passed through natively**
|
|
69
|
-
with argv-style quoting — no string re-parsing, no quoting bugs.
|
|
70
|
-
|
|
71
|
-
## Use with your agent harness
|
|
72
|
-
|
|
73
|
-
fauxnix ships an MCP stdio server exposing a `bash` tool (plus `fauxnix_translate` and
|
|
74
|
-
`fauxnix_session`). Point any MCP-capable harness at it:
|
|
75
|
-
|
|
76
|
-
**Claude Code**
|
|
77
|
-
```bash
|
|
78
|
-
claude mcp add fauxnix -- fauxnix mcp
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
**Codex** (`~/.codex/config.toml` or `codex mcp add fauxnix -- fauxnix mcp`)
|
|
82
|
-
```toml
|
|
83
|
-
[mcp_servers.fauxnix]
|
|
84
|
-
command = "fauxnix"
|
|
85
|
-
args = ["mcp"]
|
|
86
|
-
```
|
|
87
|
-
Note: in non-interactive `codex exec` mode, MCP tool calls are auto-denied by
|
|
88
|
-
the approval layer; pass `--dangerously-bypass-approvals-and-sandbox` (or run
|
|
89
|
-
interactively and approve once).
|
|
90
|
-
|
|
91
|
-
**OpenCode** (`opencode.json`)
|
|
92
|
-
```json
|
|
93
|
-
{
|
|
94
|
-
"mcp": {
|
|
95
|
-
"fauxnix": { "type": "local", "command": ["fauxnix", "mcp"] }
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
**Kimi Code** — unlike the others, MCP servers live in a JSON file, not the
|
|
101
|
-
TOML config: `~/.kimi-code/mcp.json`
|
|
102
|
-
```json
|
|
103
|
-
{
|
|
104
|
-
"mcpServers": {
|
|
105
|
-
"fauxnix": { "command": "fauxnix", "args": ["mcp"] }
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
**Any MCP client** — stdio server: `fauxnix mcp`. The tool name is `bash` (override with
|
|
111
|
-
`FAUXNIX_TOOL_NAME`). Tool description already teaches the model the supported subset, so no
|
|
112
|
-
system-prompt changes are required.
|
|
113
|
-
|
|
114
|
-
The MCP session persists `cwd`, environment variables, `export`/`unset` and `cd -`/OLDPWD across
|
|
115
|
-
tool calls — it behaves like a logged-in shell, not a stateless `exec`.
|
|
116
|
-
|
|
117
|
-
## What's translated
|
|
118
|
-
|
|
119
|
-
~105 commands, all output-matched against real GNU coreutils on Windows (Git Bash) during
|
|
120
|
-
development:
|
|
121
|
-
|
|
122
|
-
- **files**: `ls cp mv rm mkdir rmdir touch mktemp ln readlink realpath basename dirname stat file du df find chmod chown diff`
|
|
123
|
-
- **text filters**: `grep egrep sed awk sort uniq cut tr` — sed/awk scripts are parsed at
|
|
124
|
-
translate time (unsupported constructs throw named errors, never silently misbehave)
|
|
125
|
-
- **text I/O**: `echo printf cat head tail wc tee nl tac md5sum sha1sum sha256sum base64 seq yes xargs`
|
|
126
|
-
- **shell/system**: `cd pwd export unset env printenv ps kill pkill pgrep sleep which type whoami
|
|
127
|
-
id groups date uname hostname uptime free nproc clear true false test [ : pushd popd dirs sudo
|
|
128
|
-
timeout man history less more source . eval exit alias set`
|
|
129
|
-
- **network**: `curl wget ping netstat ss ip ifconfig nslookup dig host`
|
|
130
|
-
- **archives**: `tar gzip gunzip zcat zip unzip`
|
|
131
|
-
|
|
132
|
-
Plus shell syntax: pipes, `&&` / `||` / `;`, redirections (`> >> 2> 2>&1 < &>`, `/dev/null`),
|
|
133
|
-
quoting, `$VAR` `$(...)` command substitution, `VAR=x cmd` prefixes, `~` expansion, and
|
|
134
|
-
POSIX-style path normalization (`/tmp`, `/d/foo` → `D:\foo`).
|
|
135
|
-
|
|
136
|
-
Exit codes follow bash conventions: 0 ok, 1 fail, 2 usage/serious, 127 command not found,
|
|
137
|
-
124 timeout.
|
|
138
|
-
|
|
139
|
-
## How it works
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
bash command ──parser──▶ AST ──translator──▶ PowerShell script ──executor──▶ powershell.exe
|
|
143
|
-
│
|
|
144
|
-
agent ◀── GNU-style output, bash-style errors ◀── decoder (UTF-8 → GBK fallback) ◀┘
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
- **Deterministic translation, zero LLM calls** at runtime.
|
|
148
|
-
- Each command maps to a generator that emits a self-contained PowerShell block honoring the
|
|
149
|
-
"Fauxnix contract": string-per-line stdout, `[Console]::Error.WriteLine` for bash-style
|
|
150
|
-
stderr, `$script:fx_exit` for exit codes, `$input` for stdin.
|
|
151
|
-
- The executor wraps every script with UTF-8 enforcement (`[Console]::OutputEncoding`,
|
|
152
|
-
`$OutputEncoding`, `chcp 65001`), decodes output as strict-UTF-8 with a GBK(936) fallback for
|
|
153
|
-
legacy native tools, strips CLIXML serialization and PowerShell noise from stderr, and rewrites
|
|
154
|
-
common PowerShell errors (including zh-CN locale messages) into bash phrasing.
|
|
155
|
-
- Scripts run via `-EncodedCommand` (UTF-16LE) and transparently fall back to a temp `.ps1` file
|
|
156
|
-
when the 32 KB command-line limit would be exceeded.
|
|
157
|
-
|
|
158
|
-
## Known deviations (honest list)
|
|
159
|
-
|
|
160
|
-
fauxnix optimizes for the commands agents actually run. Documented deviations:
|
|
161
|
-
|
|
162
|
-
- `
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
- `
|
|
167
|
-
|
|
168
|
-
- `
|
|
169
|
-
|
|
170
|
-
-
|
|
171
|
-
|
|
172
|
-
- `
|
|
173
|
-
|
|
174
|
-
- `
|
|
175
|
-
|
|
176
|
-
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
1
|
+
# fauxnix
|
|
2
|
+
|
|
3
|
+
**Run Linux-style commands on Windows — natively, deterministically, with no VM and no WSL.**
|
|
4
|
+
|
|
5
|
+
fauxnix is a bash→PowerShell translation layer built for AI agents. Your agent keeps writing the
|
|
6
|
+
bash it already knows (`ls -la | grep foo`, `find . -name '*.ts' | wc -l`, `kill -9 1234`), and
|
|
7
|
+
fauxnix deterministically translates each command into PowerShell, executes it natively, and hands
|
|
8
|
+
back output that looks like GNU/Linux: `ls -l` columns, bash-style error messages, coreutils exit
|
|
9
|
+
codes, UTF-8/GBK handled automatically.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
$ fauxnix "ls -la src | head -2"
|
|
13
|
+
-rw-r--r-- 1 me me 1204 Aug 16 09:12 ast.ts
|
|
14
|
+
-rw-r--r-- 1 me me 8192 Aug 16 09:12 cli.ts
|
|
15
|
+
|
|
16
|
+
$ fauxnix "cat nope.txt"
|
|
17
|
+
cat: nope.txt: No such file or directory # not a PowerShell stack trace
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Why
|
|
21
|
+
|
|
22
|
+
LLM agents are dramatically better at bash than at PowerShell — bash dominates training data, so
|
|
23
|
+
models on Windows often produce "looks right, doesn't run" commands (wrong quoting, `curl` that
|
|
24
|
+
isn't curl, mojibake from codepage mismatches, inscrutable `CategoryInfo` error dumps). Existing
|
|
25
|
+
solutions are either a full VM (WSL — heavy, wrong filesystem, separate environment) or plain
|
|
26
|
+
shell wrappers (still PowerShell underneath).
|
|
27
|
+
|
|
28
|
+
fauxnix takes the third road: **translate, don't emulate**. A large, high-value subset of the
|
|
29
|
+
Linux command line — file ops, text processing, process management, archives, networking basics —
|
|
30
|
+
maps cleanly onto PowerShell + .NET. fauxnix implements that subset faithfully and *fails loudly
|
|
31
|
+
and helpfully* on what it can't translate, so the agent never gets silently-wrong results.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install -g fauxnix-cli
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or from source:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/20000419/fauxnix && cd fauxnix && npm install -g .
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
> npm package name is `fauxnix-cli` (the `fauxnix` name on npm belongs to an
|
|
46
|
+
> unrelated 2015 websocket library); the installed command is still `fauxnix`.
|
|
47
|
+
|
|
48
|
+
Requires: Windows with PowerShell 5.1+ (built-in) and Node.js ≥ 18.
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# one-off commands
|
|
54
|
+
fauxnix "ls -la"
|
|
55
|
+
fauxnix "grep -rn TODO src | wc -l"
|
|
56
|
+
fauxnix "cat log.txt | grep -i error | sort | uniq -c"
|
|
57
|
+
|
|
58
|
+
# see what a command becomes (great for debugging / learning PS)
|
|
59
|
+
fauxnix translate "find . -name '*.log' -mtime +7 -delete"
|
|
60
|
+
|
|
61
|
+
# check your environment
|
|
62
|
+
fauxnix check
|
|
63
|
+
|
|
64
|
+
# run the MCP stdio server (what agent harnesses connect to)
|
|
65
|
+
fauxnix mcp
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Unknown commands (git, node, npm, python, cargo, gh, docker, ...) are **passed through natively**
|
|
69
|
+
with argv-style quoting — no string re-parsing, no quoting bugs.
|
|
70
|
+
|
|
71
|
+
## Use with your agent harness
|
|
72
|
+
|
|
73
|
+
fauxnix ships an MCP stdio server exposing a `bash` tool (plus `fauxnix_translate` and
|
|
74
|
+
`fauxnix_session`). Point any MCP-capable harness at it:
|
|
75
|
+
|
|
76
|
+
**Claude Code**
|
|
77
|
+
```bash
|
|
78
|
+
claude mcp add fauxnix -- fauxnix mcp
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Codex** (`~/.codex/config.toml` or `codex mcp add fauxnix -- fauxnix mcp`)
|
|
82
|
+
```toml
|
|
83
|
+
[mcp_servers.fauxnix]
|
|
84
|
+
command = "fauxnix"
|
|
85
|
+
args = ["mcp"]
|
|
86
|
+
```
|
|
87
|
+
Note: in non-interactive `codex exec` mode, MCP tool calls are auto-denied by
|
|
88
|
+
the approval layer; pass `--dangerously-bypass-approvals-and-sandbox` (or run
|
|
89
|
+
interactively and approve once).
|
|
90
|
+
|
|
91
|
+
**OpenCode** (`opencode.json`)
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"mcp": {
|
|
95
|
+
"fauxnix": { "type": "local", "command": ["fauxnix", "mcp"] }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Kimi Code** — unlike the others, MCP servers live in a JSON file, not the
|
|
101
|
+
TOML config: `~/.kimi-code/mcp.json`
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"mcpServers": {
|
|
105
|
+
"fauxnix": { "command": "fauxnix", "args": ["mcp"] }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Any MCP client** — stdio server: `fauxnix mcp`. The tool name is `bash` (override with
|
|
111
|
+
`FAUXNIX_TOOL_NAME`). Tool description already teaches the model the supported subset, so no
|
|
112
|
+
system-prompt changes are required.
|
|
113
|
+
|
|
114
|
+
The MCP session persists `cwd`, environment variables, `export`/`unset` and `cd -`/OLDPWD across
|
|
115
|
+
tool calls — it behaves like a logged-in shell, not a stateless `exec`.
|
|
116
|
+
|
|
117
|
+
## What's translated
|
|
118
|
+
|
|
119
|
+
~105 commands, all output-matched against real GNU coreutils on Windows (Git Bash) during
|
|
120
|
+
development:
|
|
121
|
+
|
|
122
|
+
- **files**: `ls cp mv rm mkdir rmdir touch mktemp ln readlink realpath basename dirname stat file du df find chmod chown diff`
|
|
123
|
+
- **text filters**: `grep egrep sed awk sort uniq cut tr` — sed/awk scripts are parsed at
|
|
124
|
+
translate time (unsupported constructs throw named errors, never silently misbehave)
|
|
125
|
+
- **text I/O**: `echo printf cat head tail wc tee nl tac md5sum sha1sum sha256sum base64 seq yes xargs`
|
|
126
|
+
- **shell/system**: `cd pwd export unset env printenv ps kill pkill pgrep sleep which type whoami
|
|
127
|
+
id groups date uname hostname uptime free nproc clear true false test [ [[ : pushd popd dirs sudo
|
|
128
|
+
timeout man history less more source . eval exit alias set`
|
|
129
|
+
- **network**: `curl wget ping netstat ss ip ifconfig nslookup dig host`
|
|
130
|
+
- **archives**: `tar gzip gunzip zcat zip unzip`
|
|
131
|
+
|
|
132
|
+
Plus shell syntax: pipes, `&&` / `||` / `;`, redirections (`> >> 2> 2>&1 < &>`, `/dev/null`),
|
|
133
|
+
quoting, `$VAR` `$(...)` command substitution, `VAR=x cmd` prefixes, `~` expansion, and
|
|
134
|
+
POSIX-style path normalization (`/tmp`, `/d/foo` → `D:\foo`).
|
|
135
|
+
|
|
136
|
+
Exit codes follow bash conventions: 0 ok, 1 fail, 2 usage/serious, 127 command not found,
|
|
137
|
+
124 timeout.
|
|
138
|
+
|
|
139
|
+
## How it works
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
bash command ──parser──▶ AST ──translator──▶ PowerShell script ──executor──▶ powershell.exe
|
|
143
|
+
│
|
|
144
|
+
agent ◀── GNU-style output, bash-style errors ◀── decoder (UTF-8 → GBK fallback) ◀┘
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
- **Deterministic translation, zero LLM calls** at runtime.
|
|
148
|
+
- Each command maps to a generator that emits a self-contained PowerShell block honoring the
|
|
149
|
+
"Fauxnix contract": string-per-line stdout, `[Console]::Error.WriteLine` for bash-style
|
|
150
|
+
stderr, `$script:fx_exit` for exit codes, `$input` for stdin.
|
|
151
|
+
- The executor wraps every script with UTF-8 enforcement (`[Console]::OutputEncoding`,
|
|
152
|
+
`$OutputEncoding`, `chcp 65001`), decodes output as strict-UTF-8 with a GBK(936) fallback for
|
|
153
|
+
legacy native tools, strips CLIXML serialization and PowerShell noise from stderr, and rewrites
|
|
154
|
+
common PowerShell errors (including zh-CN locale messages) into bash phrasing.
|
|
155
|
+
- Scripts run via `-EncodedCommand` (UTF-16LE) and transparently fall back to a temp `.ps1` file
|
|
156
|
+
when the 32 KB command-line limit would be exceeded.
|
|
157
|
+
|
|
158
|
+
## Known deviations (honest list)
|
|
159
|
+
|
|
160
|
+
fauxnix optimizes for the commands agents actually run. Documented deviations:
|
|
161
|
+
|
|
162
|
+
- `X=1` standalone assignments follow `export` semantics (one session-wide environment; bash's
|
|
163
|
+
shell-var vs exported-var distinction does not exist), and a same-segment prefix is visible to
|
|
164
|
+
`$VAR` inside the command's own words (`Z=in [[ $Z == in ]]` is true here, false in bash where
|
|
165
|
+
word expansion precedes the temporary environment).
|
|
166
|
+
- `yes` is capped at 65,536 lines — PS 5.1 pipelines cannot signal upstream producers to stop, so
|
|
167
|
+
an unbounded `yes | head` would hang.
|
|
168
|
+
- `tail -f`, `source`, `eval`, `alias`, heredocs, backticks, shell control flow (`if`/`for`/`while`)
|
|
169
|
+
and background `&` are rejected with actionable error messages instead of misbehaving.
|
|
170
|
+
- `chmod` maps only the read-only bit; exec bits are no-ops on Windows. `chown` is a silent no-op
|
|
171
|
+
(as in Git Bash).
|
|
172
|
+
- `ps aux` columns are approximations (no per-process CPU% accounting, USER shows `?`).
|
|
173
|
+
- `gzip -c`/pipeline stdin is text-faithful, not byte-faithful; file-mode `gzip f` is byte-exact.
|
|
174
|
+
- A pipeline producing exactly one line, piped into `wc -l`, counts that line (bash would count 0
|
|
175
|
+
if the producer omitted the trailing newline). `printf 'x' | md5sum` stays byte-exact.
|
|
176
|
+
- `sed`/`awk` support the common subset; hold-space, labels, arrays, loops throw named
|
|
177
|
+
"not supported" errors at translate time.
|
|
178
|
+
- `curl`/`wget` refuse loopback/private/reserved addresses (localhost, 127.x, ::1, 10.x,
|
|
179
|
+
172.16–31.x, 192.168.x, 169.254.x) as a safety default for agent-driven HTTP.
|
|
180
|
+
- **Native-tool pipelines vs encoding**: PS 5.1 has a single console-encoding knob, so
|
|
181
|
+
piping localized admin tools (ipconfig, tasklist — GBK on zh-CN) and UTF-8-native dev
|
|
182
|
+
tools (node, curl) cannot both decode cleanly mid-pipeline. Default favors UTF-8 dev
|
|
183
|
+
tools; set `FAUXNIX_NATIVE_ENCODING=ansi` when your agents grep Chinese output of
|
|
184
|
+
native Windows admin tools. **File reads are always sniffed per file** (UTF-8 strict →
|
|
185
|
+
GBK fallback), so grep/sed/awk over GBK *files* works in either mode — unlike Git Bash,
|
|
186
|
+
which only matches the encoding its locale assumes.
|
|
187
|
+
|
|
188
|
+
## Development
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
npm install
|
|
192
|
+
npm test # unit + real-PowerShell integration suite (Windows only, auto-skipped elsewhere)
|
|
193
|
+
npm run build
|
|
194
|
+
npx tsx scratch/run.mjs "any bash command" # quick live check
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Architecture map: `src/parser.ts` (bash subset → AST) · `src/translator.ts` (AST → PowerShell +
|
|
198
|
+
executor wrapper) · `src/executor.ts` (spawn, redirects, session persistence) ·
|
|
199
|
+
`src/commands/*.ts` (per-command generators) · `src/mcp.ts` (MCP server) · `src/cli.ts`.
|
|
200
|
+
|
|
201
|
+
## License
|
|
202
|
+
|
|
203
|
+
MIT © 20000419
|
package/dist/ast.d.ts
CHANGED
|
@@ -32,7 +32,8 @@ export interface SimpleCommand {
|
|
|
32
32
|
kind: 'SimpleCommand';
|
|
33
33
|
/** `VAR=value` prefixes before the command name. */
|
|
34
34
|
assignments: Assignment[];
|
|
35
|
-
|
|
35
|
+
/** Command word; null for an assignment-only segment (`X=1; cmd`). */
|
|
36
|
+
name: Word | null;
|
|
36
37
|
args: Word[];
|
|
37
38
|
redirects: Redirect[];
|
|
38
39
|
}
|
|
@@ -51,6 +52,7 @@ export type Word = WordPart[];
|
|
|
51
52
|
export type WordPart = {
|
|
52
53
|
kind: 'Text';
|
|
53
54
|
text: string;
|
|
55
|
+
escaped?: boolean;
|
|
54
56
|
} | {
|
|
55
57
|
kind: 'SingleQuoted';
|
|
56
58
|
text: string;
|
|
@@ -65,6 +67,10 @@ export type WordPart = {
|
|
|
65
67
|
cmd: string;
|
|
66
68
|
};
|
|
67
69
|
export declare function wordToString(w: Word): string;
|
|
70
|
+
/** True when every part is unquoted Text and the concatenation equals `tok`. */
|
|
71
|
+
export declare function isUnquotedLiteral(w: Word, tok: string): boolean;
|
|
72
|
+
/** True when no part is single- or double-quoted. */
|
|
73
|
+
export declare function isFullyUnquoted(w: Word): boolean;
|
|
68
74
|
/** Best-effort "raw literal" view: is this word free of interpolation? */
|
|
69
75
|
export declare function isLiteralWord(w: Word): boolean;
|
|
70
76
|
export declare class FauxnixParseError extends Error {
|
package/dist/ast.js
CHANGED
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
export function wordToString(w) {
|
|
18
18
|
return w.map(partToString).join('');
|
|
19
19
|
}
|
|
20
|
+
/** True when every part is unquoted Text and the concatenation equals `tok`. */
|
|
21
|
+
export function isUnquotedLiteral(w, tok) {
|
|
22
|
+
return (w.length > 0 &&
|
|
23
|
+
w.every((p) => p.kind === 'Text' && !p.escaped) &&
|
|
24
|
+
wordToString(w) === tok);
|
|
25
|
+
}
|
|
26
|
+
/** True when no part is single- or double-quoted. */
|
|
27
|
+
export function isFullyUnquoted(w) {
|
|
28
|
+
return w.every((p) => p.kind !== 'SingleQuoted' && p.kind !== 'DoubleQuoted');
|
|
29
|
+
}
|
|
20
30
|
function partToString(p) {
|
|
21
31
|
switch (p.kind) {
|
|
22
32
|
case 'Text':
|
package/dist/cli.js
CHANGED
|
@@ -6,18 +6,18 @@ import { registeredNames } from './registry.js';
|
|
|
6
6
|
import { encodeCommand } from './encoding.js';
|
|
7
7
|
import { startMcpServer } from './mcp.js';
|
|
8
8
|
import './commands/install-all.js';
|
|
9
|
-
const USAGE = `fauxnix — run Linux-style commands on Windows via PowerShell translation
|
|
10
|
-
|
|
11
|
-
Usage:
|
|
12
|
-
fauxnix "ls -la | head -5" translate + execute a bash-style command
|
|
13
|
-
fauxnix -c "cmd" same as above
|
|
14
|
-
fauxnix translate "cmd" show the PowerShell translation only
|
|
15
|
-
fauxnix mcp start the MCP stdio server (for agent harnesses)
|
|
16
|
-
fauxnix list list translated commands
|
|
17
|
-
fauxnix check verify the local PowerShell environment
|
|
18
|
-
fauxnix --version
|
|
19
|
-
|
|
20
|
-
Notes:
|
|
9
|
+
const USAGE = `fauxnix — run Linux-style commands on Windows via PowerShell translation
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
fauxnix "ls -la | head -5" translate + execute a bash-style command
|
|
13
|
+
fauxnix -c "cmd" same as above
|
|
14
|
+
fauxnix translate "cmd" show the PowerShell translation only
|
|
15
|
+
fauxnix mcp start the MCP stdio server (for agent harnesses)
|
|
16
|
+
fauxnix list list translated commands
|
|
17
|
+
fauxnix check verify the local PowerShell environment
|
|
18
|
+
fauxnix --version
|
|
19
|
+
|
|
20
|
+
Notes:
|
|
21
21
|
Unknown commands (git, node, npm, python, cargo, ...) pass through and run natively.`;
|
|
22
22
|
export async function runCli(argv) {
|
|
23
23
|
if (argv.length === 0) {
|
|
@@ -26,7 +26,7 @@ export async function runCli(argv) {
|
|
|
26
26
|
}
|
|
27
27
|
const [verb, ...rest] = argv;
|
|
28
28
|
if (verb === '--version' || verb === '-v') {
|
|
29
|
-
console.log('fauxnix 0.
|
|
29
|
+
console.log('fauxnix 0.3.0');
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
if (verb === 'list') {
|