fauxnix-cli 0.1.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/LICENSE +21 -0
- package/README.md +179 -0
- package/dist/ast.d.ts +72 -0
- package/dist/ast.js +43 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +91 -0
- package/dist/commands/archive.d.ts +2 -0
- package/dist/commands/archive.js +385 -0
- package/dist/commands/files.d.ts +2 -0
- package/dist/commands/files.js +721 -0
- package/dist/commands/install-all.d.ts +2 -0
- package/dist/commands/install-all.js +17 -0
- package/dist/commands/net.d.ts +2 -0
- package/dist/commands/net.js +533 -0
- package/dist/commands/sysinfo.d.ts +2 -0
- package/dist/commands/sysinfo.js +1138 -0
- package/dist/commands/text-filters.d.ts +2 -0
- package/dist/commands/text-filters.js +2281 -0
- package/dist/commands/text-io.d.ts +2 -0
- package/dist/commands/text-io.js +1164 -0
- package/dist/encoding.d.ts +7 -0
- package/dist/encoding.js +29 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +103 -0
- package/dist/executor.d.ts +27 -0
- package/dist/executor.js +299 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/mcp.d.ts +4 -0
- package/dist/mcp.js +79 -0
- package/dist/parser.d.ts +11 -0
- package/dist/parser.js +400 -0
- package/dist/registry.d.ts +79 -0
- package/dist/registry.js +145 -0
- package/dist/translator.d.ts +55 -0
- package/dist/translator.js +318 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 20000419
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
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`)
|
|
82
|
+
```toml
|
|
83
|
+
[mcp_servers.fauxnix]
|
|
84
|
+
command = "fauxnix"
|
|
85
|
+
args = ["mcp"]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**OpenCode** (`opencode.json`)
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"mcp": {
|
|
92
|
+
"fauxnix": { "type": "local", "command": ["fauxnix", "mcp"] }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Any MCP client** — stdio server: `fauxnix mcp`. The tool name is `bash` (override with
|
|
98
|
+
`FAUXNIX_TOOL_NAME`). Tool description already teaches the model the supported subset, so no
|
|
99
|
+
system-prompt changes are required.
|
|
100
|
+
|
|
101
|
+
The MCP session persists `cwd`, environment variables, `export`/`unset` and `cd -`/OLDPWD across
|
|
102
|
+
tool calls — it behaves like a logged-in shell, not a stateless `exec`.
|
|
103
|
+
|
|
104
|
+
## What's translated
|
|
105
|
+
|
|
106
|
+
~105 commands, all output-matched against real GNU coreutils on Windows (Git Bash) during
|
|
107
|
+
development:
|
|
108
|
+
|
|
109
|
+
- **files**: `ls cp mv rm mkdir rmdir touch mktemp ln readlink realpath basename dirname stat file du df find chmod chown diff`
|
|
110
|
+
- **text filters**: `grep egrep sed awk sort uniq cut tr` — sed/awk scripts are parsed at
|
|
111
|
+
translate time (unsupported constructs throw named errors, never silently misbehave)
|
|
112
|
+
- **text I/O**: `echo printf cat head tail wc tee nl tac md5sum sha1sum sha256sum base64 seq yes xargs`
|
|
113
|
+
- **shell/system**: `cd pwd export unset env printenv ps kill pkill pgrep sleep which type whoami
|
|
114
|
+
id groups date uname hostname uptime free nproc clear true false test [ : pushd popd dirs sudo
|
|
115
|
+
timeout man history less more source . eval exit alias set`
|
|
116
|
+
- **network**: `curl wget ping netstat ss ip ifconfig nslookup dig host`
|
|
117
|
+
- **archives**: `tar gzip gunzip zcat zip unzip`
|
|
118
|
+
|
|
119
|
+
Plus shell syntax: pipes, `&&` / `||` / `;`, redirections (`> >> 2> 2>&1 < &>`, `/dev/null`),
|
|
120
|
+
quoting, `$VAR` `$(...)` command substitution, `VAR=x cmd` prefixes, `~` expansion, and
|
|
121
|
+
POSIX-style path normalization (`/tmp`, `/d/foo` → `D:\foo`).
|
|
122
|
+
|
|
123
|
+
Exit codes follow bash conventions: 0 ok, 1 fail, 2 usage/serious, 127 command not found,
|
|
124
|
+
124 timeout.
|
|
125
|
+
|
|
126
|
+
## How it works
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
bash command ──parser──▶ AST ──translator──▶ PowerShell script ──executor──▶ powershell.exe
|
|
130
|
+
│
|
|
131
|
+
agent ◀── GNU-style output, bash-style errors ◀── decoder (UTF-8 → GBK fallback) ◀┘
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- **Deterministic translation, zero LLM calls** at runtime.
|
|
135
|
+
- Each command maps to a generator that emits a self-contained PowerShell block honoring the
|
|
136
|
+
"Fauxnix contract": string-per-line stdout, `[Console]::Error.WriteLine` for bash-style
|
|
137
|
+
stderr, `$script:fx_exit` for exit codes, `$input` for stdin.
|
|
138
|
+
- The executor wraps every script with UTF-8 enforcement (`[Console]::OutputEncoding`,
|
|
139
|
+
`$OutputEncoding`, `chcp 65001`), decodes output as strict-UTF-8 with a GBK(936) fallback for
|
|
140
|
+
legacy native tools, strips CLIXML serialization and PowerShell noise from stderr, and rewrites
|
|
141
|
+
common PowerShell errors (including zh-CN locale messages) into bash phrasing.
|
|
142
|
+
- Scripts run via `-EncodedCommand` (UTF-16LE) and transparently fall back to a temp `.ps1` file
|
|
143
|
+
when the 32 KB command-line limit would be exceeded.
|
|
144
|
+
|
|
145
|
+
## Known deviations (honest list)
|
|
146
|
+
|
|
147
|
+
fauxnix optimizes for the commands agents actually run. Documented deviations:
|
|
148
|
+
|
|
149
|
+
- `yes` is capped at 65,536 lines — PS 5.1 pipelines cannot signal upstream producers to stop, so
|
|
150
|
+
an unbounded `yes | head` would hang.
|
|
151
|
+
- `tail -f`, `source`, `eval`, `alias`, heredocs, backticks, shell control flow (`if`/`for`/`while`)
|
|
152
|
+
and background `&` are rejected with actionable error messages instead of misbehaving.
|
|
153
|
+
- `chmod` maps only the read-only bit; exec bits are no-ops on Windows. `chown` is a silent no-op
|
|
154
|
+
(as in Git Bash).
|
|
155
|
+
- `ps aux` columns are approximations (no per-process CPU% accounting, USER shows `?`).
|
|
156
|
+
- `gzip -c`/pipeline stdin is text-faithful, not byte-faithful; file-mode `gzip f` is byte-exact.
|
|
157
|
+
- A pipeline producing exactly one line, piped into `wc -l`, counts that line (bash would count 0
|
|
158
|
+
if the producer omitted the trailing newline). `printf 'x' | md5sum` stays byte-exact.
|
|
159
|
+
- `sed`/`awk` support the common subset; hold-space, labels, arrays, loops throw named
|
|
160
|
+
"not supported" errors at translate time.
|
|
161
|
+
- `curl`/`wget` refuse loopback/private/reserved addresses (localhost, 127.x, ::1, 10.x,
|
|
162
|
+
172.16–31.x, 192.168.x, 169.254.x) as a safety default for agent-driven HTTP.
|
|
163
|
+
|
|
164
|
+
## Development
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
npm install
|
|
168
|
+
npm test # unit + real-PowerShell integration suite (Windows only, auto-skipped elsewhere)
|
|
169
|
+
npm run build
|
|
170
|
+
npx tsx scratch/run.mjs "any bash command" # quick live check
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Architecture map: `src/parser.ts` (bash subset → AST) · `src/translator.ts` (AST → PowerShell +
|
|
174
|
+
executor wrapper) · `src/executor.ts` (spawn, redirects, session persistence) ·
|
|
175
|
+
`src/commands/*.ts` (per-command generators) · `src/mcp.ts` (MCP server) · `src/cli.ts`.
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT © 20000419
|
package/dist/ast.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fauxnix AST — a pragmatic subset of POSIX/bash command syntax.
|
|
3
|
+
*
|
|
4
|
+
* Supported:
|
|
5
|
+
* - pipelines: cmd1 | cmd2 | cmd3
|
|
6
|
+
* - lists: cmd1 ; cmd2 && cmd3 || cmd4 (newlines act as ';')
|
|
7
|
+
* - redirections: > >> 2> 2>> &> 2>&1 1>&2 <
|
|
8
|
+
* - quoting: 'literal' "interp $VAR $(cmd)"
|
|
9
|
+
* - variables: $VAR ${VAR} plus special cases ($HOME $USER $PATH ...)
|
|
10
|
+
* - command substitution: $(...) (recursively translated)
|
|
11
|
+
* - env assignment prefix: VAR=value cmd
|
|
12
|
+
*
|
|
13
|
+
* Explicitly unsupported (parser throws a helpful FauxnixError):
|
|
14
|
+
* heredocs, backticks, subshells (...), background &, control flow
|
|
15
|
+
* (if/for/while), globs inside quotes, process substitution <(...).
|
|
16
|
+
*/
|
|
17
|
+
export interface CommandList {
|
|
18
|
+
kind: 'CommandList';
|
|
19
|
+
segments: ListSegment[];
|
|
20
|
+
}
|
|
21
|
+
/** One pipeline plus the operator that connects it to the *previous* segment. */
|
|
22
|
+
export interface ListSegment {
|
|
23
|
+
pipeline: Pipeline;
|
|
24
|
+
/** ';' for the first segment, otherwise the operator seen before this one. */
|
|
25
|
+
op: ';' | '&&' | '||';
|
|
26
|
+
}
|
|
27
|
+
export interface Pipeline {
|
|
28
|
+
kind: 'Pipeline';
|
|
29
|
+
commands: SimpleCommand[];
|
|
30
|
+
}
|
|
31
|
+
export interface SimpleCommand {
|
|
32
|
+
kind: 'SimpleCommand';
|
|
33
|
+
/** `VAR=value` prefixes before the command name. */
|
|
34
|
+
assignments: Assignment[];
|
|
35
|
+
name: Word;
|
|
36
|
+
args: Word[];
|
|
37
|
+
redirects: Redirect[];
|
|
38
|
+
}
|
|
39
|
+
export interface Assignment {
|
|
40
|
+
name: string;
|
|
41
|
+
value: Word;
|
|
42
|
+
}
|
|
43
|
+
export type RedirectOp = '>' | '>>' | '2>' | '2>>' | '&>' | '&>>' | '2>&1' | '1>&2' | '<';
|
|
44
|
+
export interface Redirect {
|
|
45
|
+
op: RedirectOp;
|
|
46
|
+
/** Target path (words are already flattened; no vars in v1 targets except $VAR which is kept raw). */
|
|
47
|
+
target: string;
|
|
48
|
+
}
|
|
49
|
+
/** A word is a sequence of parts that concatenate into one argument. */
|
|
50
|
+
export type Word = WordPart[];
|
|
51
|
+
export type WordPart = {
|
|
52
|
+
kind: 'Text';
|
|
53
|
+
text: string;
|
|
54
|
+
} | {
|
|
55
|
+
kind: 'SingleQuoted';
|
|
56
|
+
text: string;
|
|
57
|
+
} | {
|
|
58
|
+
kind: 'DoubleQuoted';
|
|
59
|
+
parts: WordPart[];
|
|
60
|
+
} | {
|
|
61
|
+
kind: 'Var';
|
|
62
|
+
name: string;
|
|
63
|
+
} | {
|
|
64
|
+
kind: 'CmdSub';
|
|
65
|
+
cmd: string;
|
|
66
|
+
};
|
|
67
|
+
export declare function wordToString(w: Word): string;
|
|
68
|
+
/** Best-effort "raw literal" view: is this word free of interpolation? */
|
|
69
|
+
export declare function isLiteralWord(w: Word): boolean;
|
|
70
|
+
export declare class FauxnixParseError extends Error {
|
|
71
|
+
constructor(message: string);
|
|
72
|
+
}
|
package/dist/ast.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fauxnix AST — a pragmatic subset of POSIX/bash command syntax.
|
|
3
|
+
*
|
|
4
|
+
* Supported:
|
|
5
|
+
* - pipelines: cmd1 | cmd2 | cmd3
|
|
6
|
+
* - lists: cmd1 ; cmd2 && cmd3 || cmd4 (newlines act as ';')
|
|
7
|
+
* - redirections: > >> 2> 2>> &> 2>&1 1>&2 <
|
|
8
|
+
* - quoting: 'literal' "interp $VAR $(cmd)"
|
|
9
|
+
* - variables: $VAR ${VAR} plus special cases ($HOME $USER $PATH ...)
|
|
10
|
+
* - command substitution: $(...) (recursively translated)
|
|
11
|
+
* - env assignment prefix: VAR=value cmd
|
|
12
|
+
*
|
|
13
|
+
* Explicitly unsupported (parser throws a helpful FauxnixError):
|
|
14
|
+
* heredocs, backticks, subshells (...), background &, control flow
|
|
15
|
+
* (if/for/while), globs inside quotes, process substitution <(...).
|
|
16
|
+
*/
|
|
17
|
+
export function wordToString(w) {
|
|
18
|
+
return w.map(partToString).join('');
|
|
19
|
+
}
|
|
20
|
+
function partToString(p) {
|
|
21
|
+
switch (p.kind) {
|
|
22
|
+
case 'Text':
|
|
23
|
+
return p.text;
|
|
24
|
+
case 'SingleQuoted':
|
|
25
|
+
return p.text;
|
|
26
|
+
case 'DoubleQuoted':
|
|
27
|
+
return p.parts.map(partToString).join('');
|
|
28
|
+
case 'Var':
|
|
29
|
+
return `$${p.name}`;
|
|
30
|
+
case 'CmdSub':
|
|
31
|
+
return '$(' + p.cmd + ')';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Best-effort "raw literal" view: is this word free of interpolation? */
|
|
35
|
+
export function isLiteralWord(w) {
|
|
36
|
+
return w.every((p) => p.kind === 'Text' || p.kind === 'SingleQuoted');
|
|
37
|
+
}
|
|
38
|
+
export class FauxnixParseError extends Error {
|
|
39
|
+
constructor(message) {
|
|
40
|
+
super(message);
|
|
41
|
+
this.name = 'FauxnixParseError';
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { FauxnixSession } from './executor.js';
|
|
3
|
+
import { parseCommand } from './parser.js';
|
|
4
|
+
import { translateCommandList } from './translator.js';
|
|
5
|
+
import { registeredNames } from './registry.js';
|
|
6
|
+
import { encodeCommand } from './encoding.js';
|
|
7
|
+
import { startMcpServer } from './mcp.js';
|
|
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:
|
|
21
|
+
Unknown commands (git, node, npm, python, cargo, ...) pass through and run natively.`;
|
|
22
|
+
export async function runCli(argv) {
|
|
23
|
+
if (argv.length === 0) {
|
|
24
|
+
console.log(USAGE);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const [verb, ...rest] = argv;
|
|
28
|
+
if (verb === '--version' || verb === '-v') {
|
|
29
|
+
console.log('fauxnix 0.1.0');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (verb === 'list') {
|
|
33
|
+
const names = registeredNames();
|
|
34
|
+
console.log(names.length + ' translated commands:');
|
|
35
|
+
for (const n of names)
|
|
36
|
+
console.log(' ' + n);
|
|
37
|
+
console.log('\nAnything else (git, node, npm, python, cargo, ...) is passed through natively.');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (verb === 'check') {
|
|
41
|
+
await runCheck();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (verb === 'mcp') {
|
|
45
|
+
await startMcpServer();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (verb === 'translate') {
|
|
49
|
+
const cmd = rest.join(' ');
|
|
50
|
+
const list = parseCommand(cmd);
|
|
51
|
+
const plans = translateCommandList(list);
|
|
52
|
+
console.log(plans.map((p) => p.script).join('\n# ---- next segment ----\n'));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const cmd = verb === '-c' || verb === '-e' ? rest.join(' ') : argv.join(' ');
|
|
56
|
+
if (!cmd.trim()) {
|
|
57
|
+
console.log(USAGE);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const list = parseCommand(cmd);
|
|
61
|
+
const plans = translateCommandList(list);
|
|
62
|
+
const session = new FauxnixSession();
|
|
63
|
+
const result = await session.run(plans);
|
|
64
|
+
if (result.stdout)
|
|
65
|
+
process.stdout.write(result.stdout);
|
|
66
|
+
if (result.stderr)
|
|
67
|
+
process.stderr.write(result.stderr);
|
|
68
|
+
await session.dispose();
|
|
69
|
+
process.exit(result.exitCode);
|
|
70
|
+
}
|
|
71
|
+
const PS_ARGS = ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass'];
|
|
72
|
+
async function runCheck() {
|
|
73
|
+
console.log('powershell : powershell.exe (Windows built-in)');
|
|
74
|
+
const probeCmd = '$PSVersionTable.PSVersion.ToString()';
|
|
75
|
+
const probe = spawn('powershell.exe', [...PS_ARGS, '-EncodedCommand', encodeCommand(probeCmd)], {
|
|
76
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
77
|
+
windowsHide: true,
|
|
78
|
+
});
|
|
79
|
+
let out = '';
|
|
80
|
+
probe.stdout.on('data', (d) => (out += d.toString('utf8')));
|
|
81
|
+
const code = await new Promise((resolve) => probe.on('close', (c) => resolve(c ?? 1)));
|
|
82
|
+
if (code === 0) {
|
|
83
|
+
console.log('version : ' + out.trim());
|
|
84
|
+
console.log('commands : ' + registeredNames().length + ' translated, others pass through');
|
|
85
|
+
console.log('status : OK');
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
console.error('status : FAILED to run powershell.exe');
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
}
|
|
91
|
+
}
|