fauxnix-cli 0.11.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 +144 -141
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +61 -21
- package/dist/commands/archive.js +87 -24
- package/dist/commands/files.js +25 -11
- package/dist/commands/install-all.js +2 -1
- package/dist/commands/net.d.ts +9 -0
- package/dist/commands/net.js +51 -15
- package/dist/commands/sysinfo.d.ts +2 -1
- package/dist/commands/sysinfo.js +564 -72
- package/dist/commands/text-filters.js +53 -12
- package/dist/commands/text-io.js +72 -43
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +44 -3
- package/dist/errors.js +14 -4
- package/dist/executor.d.ts +23 -1
- package/dist/executor.js +264 -51
- package/dist/install.js +43 -2
- package/dist/mcp.d.ts +78 -1
- package/dist/mcp.js +193 -9
- package/dist/parser.js +11 -3
- package/dist/powershell.d.ts +22 -0
- package/dist/powershell.js +129 -0
- package/dist/ps-host.d.ts +42 -13
- package/dist/ps-host.js +302 -40
- package/dist/qwen-launch.d.ts +12 -0
- package/dist/qwen-launch.js +29 -0
- package/dist/registry.d.ts +22 -0
- package/dist/registry.js +109 -1
- package/dist/translator.d.ts +13 -6
- package/dist/translator.js +482 -92
- package/package.json +4 -1
package/dist/commands/archive.js
CHANGED
|
@@ -28,19 +28,89 @@ const PS_GZ_FNS = [
|
|
|
28
28
|
' $fx_gz.Close()',
|
|
29
29
|
' return ,$fx_ms.ToArray()',
|
|
30
30
|
'}',
|
|
31
|
-
'function fx-gz-
|
|
32
|
-
' $
|
|
33
|
-
' $
|
|
34
|
-
'
|
|
31
|
+
'function fx-gz-open($src, $isBytes) {',
|
|
32
|
+
' if ($isBytes) { $fx_raw = New-Object System.IO.MemoryStream(,$src) }',
|
|
33
|
+
' else { $fx_raw = [IO.File]::OpenRead($src) }',
|
|
34
|
+
' try {',
|
|
35
|
+
' return (New-Object System.IO.Compression.GZipStream($fx_raw, [System.IO.Compression.CompressionMode]::Decompress))',
|
|
36
|
+
' } catch {',
|
|
37
|
+
' $fx_raw.Dispose()',
|
|
38
|
+
' throw',
|
|
39
|
+
' }',
|
|
40
|
+
'}',
|
|
41
|
+
// Drain the complete stream before producing stdout. Besides keeping -t
|
|
42
|
+
// bounded, this preserves the old all-or-nothing behavior for malformed
|
|
43
|
+
// inputs while remembering which text decoder the second pass should use.
|
|
44
|
+
'function fx-gz-validate($src, $isBytes) {',
|
|
45
|
+
' $fx_gz = fx-gz-open $src $isBytes',
|
|
35
46
|
' $fx_buf = New-Object byte[] 65536',
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'
|
|
47
|
+
' $fx_dec = (New-Object System.Text.UTF8Encoding($false, $true)).GetDecoder()',
|
|
48
|
+
' $fx_utf8 = $true',
|
|
49
|
+
' try {',
|
|
50
|
+
' while ($true) {',
|
|
51
|
+
' $fx_n = $fx_gz.Read($fx_buf, 0, $fx_buf.Length)',
|
|
52
|
+
' if ($fx_n -le 0) { break }',
|
|
53
|
+
' if ($fx_utf8) {',
|
|
54
|
+
' try { [void]$fx_dec.GetCharCount($fx_buf, 0, $fx_n, $false) }',
|
|
55
|
+
' catch [System.Text.DecoderFallbackException] { $fx_utf8 = $false }',
|
|
56
|
+
' }',
|
|
57
|
+
' }',
|
|
58
|
+
' if ($fx_utf8) {',
|
|
59
|
+
' try { [void]$fx_dec.GetCharCount($fx_buf, 0, 0, $true) }',
|
|
60
|
+
' catch [System.Text.DecoderFallbackException] { $fx_utf8 = $false }',
|
|
61
|
+
' }',
|
|
62
|
+
' return $fx_utf8',
|
|
63
|
+
' } finally {',
|
|
64
|
+
' $fx_gz.Dispose()',
|
|
65
|
+
' }',
|
|
66
|
+
'}',
|
|
67
|
+
'function fx-gz-stream-text($src, $isBytes) {',
|
|
68
|
+
' $fx_utf8 = fx-gz-validate $src $isBytes',
|
|
69
|
+
' if ($fx_utf8) { $fx_enc = New-Object System.Text.UTF8Encoding($false, $true) }',
|
|
70
|
+
' else { try { $fx_enc = [System.Text.Encoding]::GetEncoding(936) } catch { $fx_enc = [System.Text.Encoding]::ASCII } }',
|
|
71
|
+
' $fx_gz = fx-gz-open $src $isBytes',
|
|
72
|
+
' $fx_sr = New-Object System.IO.StreamReader($fx_gz, $fx_enc, $false, 65536)',
|
|
73
|
+
' try {',
|
|
74
|
+
' while ($true) {',
|
|
75
|
+
' $fx_line = $fx_sr.ReadLine()',
|
|
76
|
+
' if ($null -eq $fx_line) { break }',
|
|
77
|
+
' Write-Output -NoEnumerate $fx_line',
|
|
78
|
+
' }',
|
|
79
|
+
' } finally {',
|
|
80
|
+
' $fx_sr.Dispose()',
|
|
81
|
+
' }',
|
|
82
|
+
'}',
|
|
83
|
+
// File output is streamed into a sibling temporary file. The destination
|
|
84
|
+
// changes only after a complete decompression, and the temporary is removed
|
|
85
|
+
// on every failed path.
|
|
86
|
+
'function fx-gz-stream-file($src, $dst) {',
|
|
87
|
+
' $fx_full = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($dst)',
|
|
88
|
+
' $fx_parent = [IO.Path]::GetDirectoryName($fx_full)',
|
|
89
|
+
" $fx_tmp = [IO.Path]::Combine($fx_parent, '.fauxnix-gzip-' + [Guid]::NewGuid().ToString('N') + '.tmp')",
|
|
90
|
+
' $fx_gz = $null',
|
|
91
|
+
' $fx_os = $null',
|
|
92
|
+
' try {',
|
|
93
|
+
' $fx_gz = fx-gz-open $src $false',
|
|
94
|
+
" $fx_os = New-Object System.IO.FileStream($fx_tmp, [IO.FileMode]::CreateNew, [IO.FileAccess]::Write, [IO.FileShare]::None)",
|
|
95
|
+
' $fx_buf = New-Object byte[] 65536',
|
|
96
|
+
' while ($true) {',
|
|
97
|
+
' $fx_n = $fx_gz.Read($fx_buf, 0, $fx_buf.Length)',
|
|
98
|
+
' if ($fx_n -le 0) { break }',
|
|
99
|
+
' $fx_os.Write($fx_buf, 0, $fx_n)',
|
|
100
|
+
' }',
|
|
101
|
+
' $fx_os.Dispose(); $fx_os = $null',
|
|
102
|
+
' $fx_gz.Dispose(); $fx_gz = $null',
|
|
103
|
+
' if ([IO.File]::Exists($fx_full)) {',
|
|
104
|
+
' $fx_null = [System.Management.Automation.Language.NullString]::Value',
|
|
105
|
+
' [IO.File]::Replace($fx_tmp, $fx_full, $fx_null)',
|
|
106
|
+
' }',
|
|
107
|
+
' else { [IO.File]::Move($fx_tmp, $fx_full) }',
|
|
108
|
+
' } catch {',
|
|
109
|
+
' if ($null -ne $fx_os) { $fx_os.Dispose() }',
|
|
110
|
+
' if ($null -ne $fx_gz) { $fx_gz.Dispose() }',
|
|
111
|
+
' if ([IO.File]::Exists($fx_tmp)) { [IO.File]::Delete($fx_tmp) }',
|
|
112
|
+
' throw',
|
|
40
113
|
' }',
|
|
41
|
-
' $fx_gz.Close()',
|
|
42
|
-
' $fx_fs.Close()',
|
|
43
|
-
' return ,$fx_ms.ToArray()',
|
|
44
114
|
'}',
|
|
45
115
|
].join('\n');
|
|
46
116
|
/** Parse GNU gzip-style argv (works for gzip/gunzip/zcat). */
|
|
@@ -121,7 +191,7 @@ function gzBlock(args, ctx, forced) {
|
|
|
121
191
|
: " [Console]::Error.WriteLine('gzip: compressed data not written to a terminal. Use -f to force compression.')",
|
|
122
192
|
' $script:fx_exit = 1',
|
|
123
193
|
].join('\n')
|
|
124
|
-
: p.decompress
|
|
194
|
+
: p.decompress || p.test
|
|
125
195
|
? [
|
|
126
196
|
// NOTE stdin fidelity limitation: pipeline stdin arrives as decoded
|
|
127
197
|
// text lines, so only gzip streams that survived the text pipeline
|
|
@@ -130,13 +200,7 @@ function gzBlock(args, ctx, forced) {
|
|
|
130
200
|
" if ($fx_txt -ne '') { $fx_txt = $fx_txt + \"`n\" }",
|
|
131
201
|
' $fx_in = [System.Text.Encoding]::UTF8.GetBytes($fx_txt)',
|
|
132
202
|
' try {',
|
|
133
|
-
' $
|
|
134
|
-
' $fx_gz = New-Object System.IO.Compression.GZipStream($fx_ms, [System.IO.Compression.CompressionMode]::Decompress)',
|
|
135
|
-
' $fx_mo = New-Object System.IO.MemoryStream',
|
|
136
|
-
' $fx_buf = New-Object byte[] 65536',
|
|
137
|
-
' while ($true) { $fx_n = $fx_gz.Read($fx_buf, 0, $fx_buf.Length); if ($fx_n -le 0) { break }; $fx_mo.Write($fx_buf, 0, $fx_n) }',
|
|
138
|
-
' $fx_gz.Close()',
|
|
139
|
-
' fx-lines (fx-dec $fx_mo.ToArray())',
|
|
203
|
+
p.test ? ' [void](fx-gz-validate $fx_in $true)' : ' fx-gz-stream-text $fx_in $true',
|
|
140
204
|
' } catch {',
|
|
141
205
|
" [Console]::Error.WriteLine('gzip: stdin: not in gzip format')",
|
|
142
206
|
' $script:fx_exit = 1',
|
|
@@ -163,14 +227,13 @@ function gzBlock(args, ctx, forced) {
|
|
|
163
227
|
' }',
|
|
164
228
|
];
|
|
165
229
|
if (p.test) {
|
|
166
|
-
fileLoop.push(' try {
|
|
230
|
+
fileLoop.push(' try { [void](fx-gz-validate $fx_f $false) }', " catch { [Console]::Error.WriteLine('gzip: ' + $fx_f + ': not in gzip format'); $script:fx_exit = 1 }", ' continue');
|
|
167
231
|
}
|
|
168
232
|
else if (p.decompress) {
|
|
169
233
|
fileLoop.push(' $fx_low = $fx_f.ToLower()', " if (-not ($fx_low.EndsWith('.gz') -or $fx_low.EndsWith('.tgz'))) {", " [Console]::Error.WriteLine('gzip: ' + $fx_f + ': unknown suffix -- ignored')", ' $script:fx_exit = 2', ' continue', ' }', ' $fx_out = $fx_f.Substring(0, $fx_f.Length - 3)', " if ($fx_low.EndsWith('.tgz')) { $fx_out = $fx_f.Substring(0, $fx_f.Length - 4) + '.tar' }", ' try {', p.stdout
|
|
170
|
-
? ' fx-
|
|
234
|
+
? ' fx-gz-stream-text $fx_f $false'
|
|
171
235
|
: [
|
|
172
|
-
'
|
|
173
|
-
' [IO.File]::WriteAllBytes($fx_out, $fx_o)',
|
|
236
|
+
' fx-gz-stream-file $fx_f $fx_out',
|
|
174
237
|
' try { (Get-Item -LiteralPath $fx_out).LastWriteTime = (Get-Item -LiteralPath $fx_f).LastWriteTime } catch {}',
|
|
175
238
|
' if (-not ' + b(p.keep) + ') { Remove-Item -LiteralPath $fx_f -Force }',
|
|
176
239
|
].join('\n'), " } catch { [Console]::Error.WriteLine('gzip: ' + $fx_f + ': not in gzip format'); $script:fx_exit = 1 }");
|
|
@@ -278,7 +341,7 @@ const zip = (args) => {
|
|
|
278
341
|
" $fx_dst = $fx_arc",
|
|
279
342
|
' $fx_rename = $false',
|
|
280
343
|
" if (-not $fx_arc.ToLower().EndsWith('.zip')) { $fx_dst = $fx_arc + '.zip'; $fx_rename = $true }",
|
|
281
|
-
' Compress-Archive -
|
|
344
|
+
' Compress-Archive -LiteralPath $fx_valid -DestinationPath $fx_dst -Force -ErrorAction Stop',
|
|
282
345
|
// PS 5.1 Compress-Archive writes `\` entry separators; rewrite them to `/`
|
|
283
346
|
// so GNU unzip/bsdtar see proper directory entries.
|
|
284
347
|
' Add-Type -AssemblyName System.IO.Compression.FileSystem',
|
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
|
/* ------------------------------------------------------------------ */
|
|
@@ -2,7 +2,7 @@ import { registerAll, registerSpecs } from '../registry.js';
|
|
|
2
2
|
import { handlers as files, specs as fileSpecs } from './files.js';
|
|
3
3
|
import { handlers as textFilters, specs as textFilterSpecs } from './text-filters.js';
|
|
4
4
|
import { handlers as textIo, specs as textIoSpecs } from './text-io.js';
|
|
5
|
-
import { handlers as sysinfo } from './sysinfo.js';
|
|
5
|
+
import { handlers as sysinfo, specs as sysinfoSpecs } from './sysinfo.js';
|
|
6
6
|
import { handlers as net } from './net.js';
|
|
7
7
|
import { handlers as archive, specs as archiveSpecs } from './archive.js';
|
|
8
8
|
/** Register every built-in Linux command translator. Side-effectful import. */
|
|
@@ -17,5 +17,6 @@ export function installAll() {
|
|
|
17
17
|
registerSpecs(textIoSpecs);
|
|
18
18
|
registerSpecs(textFilterSpecs);
|
|
19
19
|
registerSpecs(archiveSpecs);
|
|
20
|
+
registerSpecs(sysinfoSpecs);
|
|
20
21
|
}
|
|
21
22
|
installAll();
|
package/dist/commands/net.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import { Handler } from '../registry.js';
|
|
2
|
+
/**
|
|
3
|
+
* GNU wget-style default output basename for the curl fallback.
|
|
4
|
+
*
|
|
5
|
+
* A valid UTF-8 percent sequence is decoded exactly once. Malformed sequences
|
|
6
|
+
* remain literal, while characters Windows cannot put in a filename are
|
|
7
|
+
* percent-encoded again. This keeps encoded separators inside one basename
|
|
8
|
+
* instead of accidentally turning them into local path components.
|
|
9
|
+
*/
|
|
10
|
+
export declare function urlFileName(u: string): string;
|
|
2
11
|
export declare const handlers: Record<string, Handler>;
|
package/dist/commands/net.js
CHANGED
|
@@ -105,21 +105,57 @@ const curl = (args) => {
|
|
|
105
105
|
/* ------------------------------------------------------------------ */
|
|
106
106
|
/* wget */
|
|
107
107
|
/* ------------------------------------------------------------------ */
|
|
108
|
-
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
108
|
+
const WINDOWS_DEVICE_NAME = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i;
|
|
109
|
+
function percentEncodeChar(char) {
|
|
110
|
+
return Array.from(Buffer.from(char, 'utf8'), (byte) => '%' + byte.toString(16).toUpperCase()).join('');
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* GNU wget-style default output basename for the curl fallback.
|
|
114
|
+
*
|
|
115
|
+
* A valid UTF-8 percent sequence is decoded exactly once. Malformed sequences
|
|
116
|
+
* remain literal, while characters Windows cannot put in a filename are
|
|
117
|
+
* percent-encoded again. This keeps encoded separators inside one basename
|
|
118
|
+
* instead of accidentally turning them into local path components.
|
|
119
|
+
*/
|
|
120
|
+
export function urlFileName(u) {
|
|
121
|
+
let pathname;
|
|
122
|
+
try {
|
|
123
|
+
pathname = new URL(u).pathname;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return 'index.html';
|
|
127
|
+
}
|
|
128
|
+
// URL normalisation handles dot segments. A bare path or trailing slash uses
|
|
129
|
+
// wget's conventional index filename.
|
|
130
|
+
if (pathname === '' || pathname.endsWith('/'))
|
|
131
|
+
return 'index.html';
|
|
132
|
+
const rawName = pathname.slice(pathname.lastIndexOf('/') + 1);
|
|
133
|
+
let decoded = rawName;
|
|
134
|
+
try {
|
|
135
|
+
decoded = decodeURIComponent(rawName);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Keep malformed percent escapes literal so naming remains deterministic.
|
|
139
|
+
}
|
|
140
|
+
let safe = '';
|
|
141
|
+
for (const char of decoded) {
|
|
142
|
+
const code = char.codePointAt(0) ?? 0;
|
|
143
|
+
if (code <= 0x1f || code === 0x7f || /[<>:"/\\|?*]/.test(char)) {
|
|
144
|
+
safe += percentEncodeChar(char);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
safe += char;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Windows strips trailing dots/spaces and treats DOS device basenames as
|
|
151
|
+
// special even when an extension is present. Preserve the intended text in
|
|
152
|
+
// a stable, ordinary filename instead.
|
|
153
|
+
safe = safe.replace(/[. ]+$/, (suffix) => Array.from(suffix, (char) => percentEncodeChar(char)).join(''));
|
|
154
|
+
if (safe === '' || safe === '.' || safe === '..')
|
|
155
|
+
return 'index.html';
|
|
156
|
+
if (WINDOWS_DEVICE_NAME.test(safe))
|
|
157
|
+
safe = '_' + safe;
|
|
158
|
+
return safe;
|
|
123
159
|
}
|
|
124
160
|
/** Map GNU wget argv → curl.exe argv (only literal words are rewritten). */
|
|
125
161
|
function mapWgetArgs(args) {
|