fauxnix-cli 0.2.1 → 0.4.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
@@ -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
- - `yes` is capped at 65,536 lines PS 5.1 pipelines cannot signal upstream producers to stop, so
163
- an unbounded `yes | head` would hang.
164
- - `tail -f`, `source`, `eval`, `alias`, heredocs, backticks, shell control flow (`if`/`for`/`while`)
165
- and background `&` are rejected with actionable error messages instead of misbehaving.
166
- - `chmod` maps only the read-only bit; exec bits are no-ops on Windows. `chown` is a silent no-op
167
- (as in Git Bash).
168
- - `ps aux` columns are approximations (no per-process CPU% accounting, USER shows `?`).
169
- - `gzip -c`/pipeline stdin is text-faithful, not byte-faithful; file-mode `gzip f` is byte-exact.
170
- - A pipeline producing exactly one line, piped into `wc -l`, counts that line (bash would count 0
171
- if the producer omitted the trailing newline). `printf 'x' | md5sum` stays byte-exact.
172
- - `sed`/`awk` support the common subset; hold-space, labels, arrays, loops throw named
173
- "not supported" errors at translate time.
174
- - `curl`/`wget` refuse loopback/private/reserved addresses (localhost, 127.x, ::1, 10.x,
175
- 172.16–31.x, 192.168.x, 169.254.x) as a safety default for agent-driven HTTP.
176
- - **Native-tool pipelines vs encoding**: PS 5.1 has a single console-encoding knob, so
177
- piping localized admin tools (ipconfig, tasklist — GBK on zh-CN) and UTF-8-native dev
178
- tools (node, curl) cannot both decode cleanly mid-pipeline. Default favors UTF-8 dev
179
- tools; set `FAUXNIX_NATIVE_ENCODING=ansi` when your agents grep Chinese output of
180
- native Windows admin tools. **File reads are always sniffed per file** (UTF-8 strict
181
- GBK fallback), so grep/sed/awk over GBK *files* works in either mode unlike Git Bash,
182
- which only matches the encoding its locale assumes.
183
-
184
- ## Development
185
-
186
- ```bash
187
- npm install
188
- npm test # unit + real-PowerShell integration suite (Windows only, auto-skipped elsewhere)
189
- npm run build
190
- npx tsx scratch/run.mjs "any bash command" # quick live check
191
- ```
192
-
193
- Architecture map: `src/parser.ts` (bash subset → AST) · `src/translator.ts` (AST → PowerShell +
194
- executor wrapper) · `src/executor.ts` (spawn, redirects, session persistence) ·
195
- `src/commands/*.ts` (per-command generators) · `src/mcp.ts` (MCP server) · `src/cli.ts`.
196
-
197
- ## License
198
-
199
- MIT © 20000419
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
@@ -6,7 +6,7 @@
6
6
  * - lists: cmd1 ; cmd2 && cmd3 || cmd4 (newlines act as ';')
7
7
  * - redirections: > >> 2> 2>> &> 2>&1 1>&2 <
8
8
  * - quoting: 'literal' "interp $VAR $(cmd)"
9
- * - variables: $VAR ${VAR} plus special cases ($HOME $USER $PATH ...)
9
+ * - variables: $VAR ${VAR} ${VAR[n]} plus special cases ($HOME $USER $PATH ...)
10
10
  * - command substitution: $(...) (recursively translated)
11
11
  * - env assignment prefix: VAR=value cmd
12
12
  *
@@ -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
- name: Word;
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;
@@ -60,11 +62,16 @@ export type WordPart = {
60
62
  } | {
61
63
  kind: 'Var';
62
64
  name: string;
65
+ index?: string;
63
66
  } | {
64
67
  kind: 'CmdSub';
65
68
  cmd: string;
66
69
  };
67
70
  export declare function wordToString(w: Word): string;
71
+ /** True when every part is unquoted Text and the concatenation equals `tok`. */
72
+ export declare function isUnquotedLiteral(w: Word, tok: string): boolean;
73
+ /** True when no part is single- or double-quoted. */
74
+ export declare function isFullyUnquoted(w: Word): boolean;
68
75
  /** Best-effort "raw literal" view: is this word free of interpolation? */
69
76
  export declare function isLiteralWord(w: Word): boolean;
70
77
  export declare class FauxnixParseError extends Error {
package/dist/ast.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * - lists: cmd1 ; cmd2 && cmd3 || cmd4 (newlines act as ';')
7
7
  * - redirections: > >> 2> 2>> &> 2>&1 1>&2 <
8
8
  * - quoting: 'literal' "interp $VAR $(cmd)"
9
- * - variables: $VAR ${VAR} plus special cases ($HOME $USER $PATH ...)
9
+ * - variables: $VAR ${VAR} ${VAR[n]} plus special cases ($HOME $USER $PATH ...)
10
10
  * - command substitution: $(...) (recursively translated)
11
11
  * - env assignment prefix: VAR=value cmd
12
12
  *
@@ -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':
@@ -26,7 +36,7 @@ function partToString(p) {
26
36
  case 'DoubleQuoted':
27
37
  return p.parts.map(partToString).join('');
28
38
  case 'Var':
29
- return `$${p.name}`;
39
+ return p.index !== undefined ? `\${${p.name}[${p.index}]}` : `$${p.name}`;
30
40
  case 'CmdSub':
31
41
  return '$(' + p.cmd + ')';
32
42
  }
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.2.1');
29
+ console.log('fauxnix 0.4.0');
30
30
  return;
31
31
  }
32
32
  if (verb === 'list') {
@@ -1,6 +1,6 @@
1
1
  import { wordToString } from '../ast.js';
2
2
  import { psStr } from '../registry.js';
3
- import { exprOfWord, operandExpr } from '../translator.js';
3
+ import { argListExpr, exprOfWord, operandExpr } from '../translator.js';
4
4
  /* ------------------------------------------------------------------ */
5
5
  /* gzip family — .NET GZipStream helpers */
6
6
  /* ------------------------------------------------------------------ */
@@ -188,7 +188,7 @@ function gzBlock(args, ctx, forced) {
188
188
  fileLoop.push(' }');
189
189
  return [
190
190
  PS_GZ_FNS,
191
- '$fx_files = @(' + (p.files.length ? p.files.map(operandExpr).join(', ') : '') + ')',
191
+ '$fx_files = ' + (p.files.length ? argListExpr(p.files, operandExpr) : '@()'),
192
192
  'if ($fx_files.Count -eq 0) {',
193
193
  stdinBranch,
194
194
  '} else {',
@@ -204,7 +204,7 @@ const zcat = (args, ctx) => gzBlock(args, ctx, { decompress: true, stdout: true
204
204
  /* ------------------------------------------------------------------ */
205
205
  const tar = (args) => {
206
206
  return [
207
- "$fx_args = @(" + args.map(exprOfWord).join(', ') + ')',
207
+ '$fx_args = ' + argListExpr(args, exprOfWord),
208
208
  // Prefer the Windows-shipped bsdtar (System32): it accepts both path
209
209
  // styles. A PATH lookup could resolve to Git Bash's GNU tar, which
210
210
  // misreads `C:\...` argv as a remote-host spec (host:path syntax).
@@ -255,10 +255,10 @@ const zip = (args) => {
255
255
  "[Console]::Error.WriteLine('zip error: Nothing to do! (fauxnix: usage: zip [-r] ARCHIVE FILES...)'); $script:fx_exit = 12");
256
256
  }
257
257
  const arc = operandExpr(rest[0]);
258
- const inputs = rest.slice(1).map(operandExpr).join(', ');
258
+ const inputs = argListExpr(rest.slice(1), operandExpr);
259
259
  return [
260
260
  note + '$fx_arc = ' + arc,
261
- '$fx_inputs = @(' + inputs + ')',
261
+ '$fx_inputs = ' + inputs,
262
262
  '$fx_valid = @()',
263
263
  'foreach ($fx_p in $fx_inputs) {',
264
264
  ' if (Test-Path -LiteralPath $fx_p) { $fx_valid += $fx_p }',