fauxnix-cli 0.12.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -152
- package/dist/commands/files.js +25 -11
- package/dist/commands/sysinfo.js +9 -7
- package/dist/commands/text-filters.js +17 -1
- package/dist/errors.js +7 -1
- package/dist/executor.d.ts +19 -0
- package/dist/executor.js +70 -0
- package/dist/facade.d.ts +1 -0
- package/dist/facade.js +106 -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 +27 -20
- package/dist/translator.js +85 -11
- package/package.json +2 -1
package/dist/translator.js
CHANGED
|
@@ -279,7 +279,7 @@ export function varExpr(name, index, param, length = false, extra) {
|
|
|
279
279
|
case 'HOME':
|
|
280
280
|
return '$HOME';
|
|
281
281
|
case 'PWD':
|
|
282
|
-
return '$PWD.Path';
|
|
282
|
+
return 'fx-posix([string]$PWD.Path)';
|
|
283
283
|
case 'USER':
|
|
284
284
|
case 'LOGNAME':
|
|
285
285
|
return '$env:USERNAME';
|
|
@@ -290,7 +290,7 @@ export function varExpr(name, index, param, length = false, extra) {
|
|
|
290
290
|
case 'TERM':
|
|
291
291
|
return "'xterm-256color'";
|
|
292
292
|
case 'OLDPWD':
|
|
293
|
-
return '$env:FAUXNIX_OLDPWD';
|
|
293
|
+
return 'fx-posix([string]$env:FAUXNIX_OLDPWD)';
|
|
294
294
|
case '?':
|
|
295
295
|
return '[string]$fx_prev';
|
|
296
296
|
case '$':
|
|
@@ -1275,6 +1275,7 @@ const WRAP_HELPER_ORDER = [
|
|
|
1275
1275
|
'fx-winargv',
|
|
1276
1276
|
'fx-cmdargv',
|
|
1277
1277
|
'fx-native',
|
|
1278
|
+
'fx-posix',
|
|
1278
1279
|
];
|
|
1279
1280
|
const WRAP_HELPER_DEPS = {
|
|
1280
1281
|
'fx-readlines': [],
|
|
@@ -1301,6 +1302,7 @@ const WRAP_HELPER_DEPS = {
|
|
|
1301
1302
|
'fx-winargv': [],
|
|
1302
1303
|
'fx-cmdargv': ['fx-winargv'],
|
|
1303
1304
|
'fx-native': ['fx-cmdargv'],
|
|
1305
|
+
'fx-posix': [],
|
|
1304
1306
|
};
|
|
1305
1307
|
/** Helpers the body calls that wrapScript still has to emit (not already defined there). */
|
|
1306
1308
|
function wrapHelpersNeeded(body) {
|
|
@@ -1349,13 +1351,13 @@ function wrapCwdPreamble() {
|
|
|
1349
1351
|
'$script:fx_exit = 0',
|
|
1350
1352
|
'$fx_prev = 0',
|
|
1351
1353
|
'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 {} }',
|
|
1354
|
+
'if ($env:FAUXNIX_CWD -and (Get-Location).ProviderPath -cne $env:FAUXNIX_CWD) { try { Set-Location -LiteralPath $env:FAUXNIX_CWD } catch {} }',
|
|
1353
1355
|
// capture AFTER the session cwd is applied — OLDPWD must refer to the
|
|
1354
1356
|
// shell's previous directory, not the host process' startup directory
|
|
1355
1357
|
'$fx_oldcwd = (Get-Location).ProviderPath',
|
|
1356
1358
|
// .NET APIs (ReadAllBytes & friends) resolve relative paths against the
|
|
1357
1359
|
// process working directory, NOT the PS location — keep them in sync.
|
|
1358
|
-
'try { [Environment]::CurrentDirectory
|
|
1360
|
+
'try { if ([Environment]::CurrentDirectory -cne $fx_oldcwd) { [Environment]::CurrentDirectory = $fx_oldcwd } } catch {}',
|
|
1359
1361
|
];
|
|
1360
1362
|
}
|
|
1361
1363
|
function wrapBodyAndPersist(body, exitProcess) {
|
|
@@ -1370,12 +1372,20 @@ function wrapBodyAndPersist(body, exitProcess) {
|
|
|
1370
1372
|
' $script:fx_exit = 1',
|
|
1371
1373
|
'}',
|
|
1372
1374
|
'# persist session cwd and environment for the next segment',
|
|
1373
|
-
|
|
1375
|
+
...(exitProcess ? [
|
|
1376
|
+
'try { [IO.File]::WriteAllText($env:FAUXNIX_CWD_FILE, (Get-Location).Path) } catch {}',
|
|
1377
|
+
] : [
|
|
1378
|
+
'try { [FauxnixSessionState]::SaveCwd($env:FAUXNIX_CWD_FILE, (Get-Location).Path) } catch {}',
|
|
1379
|
+
]),
|
|
1374
1380
|
'if ((Get-Location).Path -ne $fx_oldcwd) { $env:FAUXNIX_OLDPWD = $fx_oldcwd }',
|
|
1375
1381
|
'try {',
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1382
|
+
...(exitProcess ? [
|
|
1383
|
+
' $envObj = @{}',
|
|
1384
|
+
' Get-ChildItem Env: | ForEach-Object { $envObj[$_.Name] = $_.Value }',
|
|
1385
|
+
' [IO.File]::WriteAllText($env:FAUXNIX_ENV_FILE, (ConvertTo-Json $envObj -Compress))',
|
|
1386
|
+
] : [
|
|
1387
|
+
' [FauxnixSessionState]::SaveEnvironment($env:FAUXNIX_ENV_FILE)',
|
|
1388
|
+
]),
|
|
1379
1389
|
'} catch {}',
|
|
1380
1390
|
];
|
|
1381
1391
|
if (exitProcess)
|
|
@@ -1530,12 +1540,12 @@ export function wrapScript(body, opts = {}) {
|
|
|
1530
1540
|
' if ($fx_pair.Substring(0, $fx_eq) -ceq $n) { return (fx-svdec $fx_pair.Substring($fx_eq + 1)) }',
|
|
1531
1541
|
' }',
|
|
1532
1542
|
" if ($n -ceq 'HOME') { return [string]$HOME }",
|
|
1533
|
-
" if ($n -ceq 'PWD') { return [string]$PWD.Path }",
|
|
1543
|
+
" if ($n -ceq 'PWD') { return fx-posix([string]$PWD.Path) }",
|
|
1534
1544
|
" if ($n -ceq 'USER' -or $n -ceq 'LOGNAME') { return [string]$env:USERNAME }",
|
|
1535
1545
|
" if ($n -ceq 'PATH') { return [string]$env:PATH }",
|
|
1536
1546
|
" if ($n -ceq 'SHELL') { return 'powershell' }",
|
|
1537
1547
|
" if ($n -ceq 'TERM') { return 'xterm-256color' }",
|
|
1538
|
-
" if ($n -ceq 'OLDPWD') { return $(if ($env:FAUXNIX_OLDPWD) { [string]$env:FAUXNIX_OLDPWD } else { $null }) }",
|
|
1548
|
+
" if ($n -ceq 'OLDPWD') { return $(if ($env:FAUXNIX_OLDPWD) { fx-posix([string]$env:FAUXNIX_OLDPWD) } else { $null }) }",
|
|
1539
1549
|
" if ($n -ceq 'HOSTNAME') { return [string]$env:COMPUTERNAME }",
|
|
1540
1550
|
' $ev = Get-ChildItem Env: | Where-Object { $_.Name -ceq $n } | Select-Object -First 1',
|
|
1541
1551
|
' if ($ev) { return [string]$ev.Value }',
|
|
@@ -1647,6 +1657,13 @@ export function wrapScript(body, opts = {}) {
|
|
|
1647
1657
|
' return $false',
|
|
1648
1658
|
'}',
|
|
1649
1659
|
],
|
|
1660
|
+
'fx-posix': [
|
|
1661
|
+
'function fx-posix($p) {',
|
|
1662
|
+
' $p = ([string]$p).Replace(\'\\\', \'/\')',
|
|
1663
|
+
" if ($p -match '^[A-Za-z]:') { return '/' + $p.Substring(0, 1).ToLower() + $p.Substring(2) }",
|
|
1664
|
+
' return $p',
|
|
1665
|
+
'}',
|
|
1666
|
+
],
|
|
1650
1667
|
'fx-subst': [
|
|
1651
1668
|
'function fx-subst($s, $pat, $repl, $all) {',
|
|
1652
1669
|
' if ($null -eq $s) { return \'\' }',
|
|
@@ -1846,7 +1863,7 @@ export function wrapScript(body, opts = {}) {
|
|
|
1846
1863
|
' $fx_spoolUtf8 = New-Object System.Text.UTF8Encoding $false',
|
|
1847
1864
|
' try {',
|
|
1848
1865
|
' if (-not $term) {',
|
|
1849
|
-
" if ($env:FAUXNIX_NATIVE_SPOOL_DIR) { $fx_no = Join-Path $env:FAUXNIX_NATIVE_SPOOL_DIR (([guid]::NewGuid().ToString('N')) + '.out') }",
|
|
1866
|
+
" 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
1867
|
' else { $fx_no = [IO.Path]::GetTempFileName() }',
|
|
1851
1868
|
' }',
|
|
1852
1869
|
' [void]$p.Start()',
|
|
@@ -1907,6 +1924,63 @@ if (-not ('FauxnixBoundedStream' -as [type])) {
|
|
|
1907
1924
|
Add-Type -TypeDefinition @'
|
|
1908
1925
|
using System;
|
|
1909
1926
|
using System.IO;
|
|
1927
|
+
using System.Collections;
|
|
1928
|
+
using System.Text;
|
|
1929
|
+
public static class FauxnixSessionState {
|
|
1930
|
+
private static string previousCwdPath;
|
|
1931
|
+
private static string previousCwd;
|
|
1932
|
+
private static string previousEnvironmentPath;
|
|
1933
|
+
private static string previousEnvironment;
|
|
1934
|
+
public static void SaveCwd(string path, string cwd) {
|
|
1935
|
+
if (path == previousCwdPath && cwd == previousCwd && File.Exists(path)) return;
|
|
1936
|
+
File.WriteAllText(path, cwd, new UTF8Encoding(false));
|
|
1937
|
+
previousCwdPath = path;
|
|
1938
|
+
previousCwd = cwd;
|
|
1939
|
+
}
|
|
1940
|
+
private static void AppendJsonString(StringBuilder json, string value) {
|
|
1941
|
+
json.Append((char)34);
|
|
1942
|
+
foreach (char c in value) {
|
|
1943
|
+
if (c == (char)34 || c == (char)92) {
|
|
1944
|
+
json.Append((char)92).Append(c);
|
|
1945
|
+
} else if (c < 32 || Char.IsSurrogate(c)) {
|
|
1946
|
+
json.Append((char)92).Append('u').Append(((int)c).ToString("x4"));
|
|
1947
|
+
} else {
|
|
1948
|
+
json.Append(c);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
json.Append((char)34);
|
|
1952
|
+
}
|
|
1953
|
+
public static void SaveEnvironment(string path) {
|
|
1954
|
+
// Keep a complete snapshot: merging with the parent's environment on a
|
|
1955
|
+
// later restart would resurrect values removed by unset.
|
|
1956
|
+
IDictionary environment = Environment.GetEnvironmentVariables();
|
|
1957
|
+
var json = new StringBuilder(4096);
|
|
1958
|
+
json.Append('{');
|
|
1959
|
+
bool first = true;
|
|
1960
|
+
var keys = new string[environment.Count];
|
|
1961
|
+
environment.Keys.CopyTo(keys, 0);
|
|
1962
|
+
Array.Sort(keys, StringComparer.Ordinal);
|
|
1963
|
+
foreach (string key in keys) {
|
|
1964
|
+
// These values are request transport metadata and are always supplied
|
|
1965
|
+
// afresh by Node; changing them does not change persistent shell state.
|
|
1966
|
+
if (String.Equals(key, "FAUXNIX_NATIVE_SPOOL_DIR", StringComparison.OrdinalIgnoreCase) ||
|
|
1967
|
+
String.Equals(key, "FAUXNIX_PREV_EXIT", StringComparison.OrdinalIgnoreCase) ||
|
|
1968
|
+
String.Equals(key, "FAUXNIX_STDIN_FILE", StringComparison.OrdinalIgnoreCase) ||
|
|
1969
|
+
String.Equals(key, "FAUXNIX_CWD", StringComparison.OrdinalIgnoreCase)) continue;
|
|
1970
|
+
if (!first) json.Append(',');
|
|
1971
|
+
first = false;
|
|
1972
|
+
AppendJsonString(json, key);
|
|
1973
|
+
json.Append(':');
|
|
1974
|
+
AppendJsonString(json, (string)environment[key]);
|
|
1975
|
+
}
|
|
1976
|
+
json.Append('}');
|
|
1977
|
+
string current = json.ToString();
|
|
1978
|
+
if (path == previousEnvironmentPath && current == previousEnvironment && File.Exists(path)) return;
|
|
1979
|
+
File.WriteAllText(path, current, new UTF8Encoding(false));
|
|
1980
|
+
previousEnvironmentPath = path;
|
|
1981
|
+
previousEnvironment = current;
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1910
1984
|
public sealed class FauxnixBoundedStream : Stream {
|
|
1911
1985
|
private readonly MemoryStream inner;
|
|
1912
1986
|
private readonly long limit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fauxnix-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.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"
|