fauxnix-cli 1.0.0 → 2.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 +49 -8
- package/dist/cli.js +18 -7
- package/dist/commands/archive.js +135 -103
- package/dist/commands/files.d.ts +2 -1
- package/dist/commands/files.js +139 -50
- package/dist/commands/gzip-node.d.ts +3 -0
- package/dist/commands/gzip-node.js +119 -0
- package/dist/commands/move-native.d.ts +1 -0
- package/dist/commands/move-native.js +82 -0
- package/dist/commands/net.js +26 -34
- package/dist/commands/sysinfo.js +7 -3
- package/dist/commands/text-filters.js +50 -116
- package/dist/commands/text-io.js +103 -88
- package/dist/commands/text-output.d.ts +14 -0
- package/dist/commands/text-output.js +29 -0
- package/dist/doctor.js +9 -12
- package/dist/encoding.d.ts +5 -0
- package/dist/encoding.js +40 -0
- package/dist/executor.js +1 -15
- package/dist/facade.js +14 -5
- package/dist/index.js +11 -5
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +162 -141
- package/dist/parser.js +18 -1
- package/dist/ps-host.js +34 -3
- package/dist/registry.d.ts +5 -0
- package/dist/registry.js +10 -5
- package/dist/runtime-support.d.ts +3 -0
- package/dist/runtime-support.js +22 -0
- package/dist/translator.d.ts +2 -1
- package/dist/translator.js +38 -38
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -15,8 +15,12 @@ back output that looks like GNU/Linux: `ls -l` columns, bash-style error message
|
|
|
15
15
|
codes, UTF-8/GBK handled automatically.
|
|
16
16
|
|
|
17
17
|
One-command install for **Claude Code · Codex · OpenCode · Kimi Code · Qwen Code**, plus any MCP
|
|
18
|
-
client. **109 translated commands ·
|
|
19
|
-
|
|
18
|
+
client. **109 translated commands · 1,044 automated tests · 270-case Git Bash differential
|
|
19
|
+
corpus plus 41 supplementary checks · zero LLM calls at runtime.**
|
|
20
|
+
|
|
21
|
+
This checkout prepares **v2.0.0**. See [migration and release notes](docs/releases/v2.0.0.md)
|
|
22
|
+
for the Node.js requirement, changed file-operation contracts and verification limits.
|
|
23
|
+
The npm badge and `@latest` examples show the published version until publication completes.
|
|
20
24
|
|
|
21
25
|
## Try it now — no install
|
|
22
26
|
|
|
@@ -49,7 +53,9 @@ config files yourself.
|
|
|
49
53
|
|
|
50
54
|
> npm package name is `fauxnix-cli` (the `fauxnix` name on npm belongs to an unrelated 2015
|
|
51
55
|
> websocket library); the installed command is `fauxnix`. Requires Windows with PowerShell 5.1+
|
|
52
|
-
> (built-in) and Node.js ≥
|
|
56
|
+
> (built-in) and Node.js ≥ 22.20.0.
|
|
57
|
+
> Node 18/20 are unsupported in v2. Current Node 22/24 LTS patches are tested.
|
|
58
|
+
> Published v1.0.0 retains its original metadata.
|
|
53
59
|
|
|
54
60
|
<details>
|
|
55
61
|
<summary><b>Manual config per harness</b></summary>
|
|
@@ -123,6 +129,14 @@ structured result per step in a single MCP round trip (stops on first nonzero ex
|
|
|
123
129
|
See [compiled MCP batch plans](docs/rfc-mcp-batch-plans.md) for timeout, budget, cancellation,
|
|
124
130
|
and preflight semantics.
|
|
125
131
|
|
|
132
|
+
### Experimental: native shell facade
|
|
133
|
+
|
|
134
|
+
`fauxnix facade` (experimental) implements the bash **process** contract — `facade -c "<cmd>"`
|
|
135
|
+
one-shots with bash argv semantics (`$0`/`$1` from trailing operands) and a persistent stdin
|
|
136
|
+
session with `<bash-input>` markers — so a harness can eventually point its built-in Bash tool
|
|
137
|
+
at a fauxnix-backed `bash.exe` instead of an MCP sidecar, with zero protocol round trips.
|
|
138
|
+
Status, launcher strategy, and security rules: [RFC — native shell facade](docs/rfc-bash-facade.md).
|
|
139
|
+
|
|
126
140
|
## Measured: your model is probably worse at PowerShell than you think
|
|
127
141
|
|
|
128
142
|
Same model (DeepSeek-V4-Pro), same 5 tasks, three execution modes on one Windows machine —
|
|
@@ -150,7 +164,7 @@ isn't curl, mojibake from codepage mismatches, inscrutable `CategoryInfo` error
|
|
|
150
164
|
| agent writes plain bash | ✓ | ✓ | ✓ | ✗ |
|
|
151
165
|
| only needs Node (no bash toolchain / VM) | ✓ | ✗ | ✗ (VM, GBs) | ✓ |
|
|
152
166
|
| native Windows filesystem & environment | ✓ | mostly | ✗ (9P bridge) | ✓ |
|
|
153
|
-
|
|
|
167
|
+
| differential compatibility | 269/270 cases identical; limits below | GNU reference | GNU tools | different contracts |
|
|
154
168
|
| CRLF / UTF-8 / GBK traps handled | ✓ | locale-dependent | ✓ | ✗ |
|
|
155
169
|
|
|
156
170
|
**If Git Bash already works for you, keep it** — we literally use it as our differential-testing
|
|
@@ -250,10 +264,33 @@ fauxnix optimizes for the commands agents actually run. Documented deviations:
|
|
|
250
264
|
(as in Git Bash).
|
|
251
265
|
- `ps aux` columns are approximations (no per-process CPU% accounting, USER shows `?`).
|
|
252
266
|
- `gzip -c`/pipeline stdin is text-faithful, not byte-faithful; file-mode `gzip f` is byte-exact.
|
|
267
|
+
- Gzip decompression and `gzip -t` use Node's strict streaming decoder, including
|
|
268
|
+
every concatenated member. Incomplete streams and checksum errors fail without
|
|
269
|
+
committing a destination or deleting the archive. Trailing non-gzip garbage is
|
|
270
|
+
an error rather than GNU's warning. Text stdout is validated before emission and
|
|
271
|
+
needs temporary disk space proportional to decoded size; `-t` discards output.
|
|
272
|
+
Standalone translated scripts require supported `node.exe` on PATH. See the
|
|
273
|
+
[strict gzip contract](docs/rfc-strict-gzip.md) for cancellation and spool limits.
|
|
274
|
+
- `mv` replaces regular files only within one volume, without predeleting the
|
|
275
|
+
destination. Cross-volume replacement, leaf reparse-point replacement, and
|
|
276
|
+
replacing an existing empty directory fail explicitly with originals retained;
|
|
277
|
+
`-f` does not bypass these limits. Existing-target `-n` still skips. Ordinary
|
|
278
|
+
absent-target moves retain PowerShell behavior and are not transactional across
|
|
279
|
+
volumes. Identity checks and rename are separate operations, not a race-proof
|
|
280
|
+
transaction. See the [move contract](docs/rfc-safe-file-move.md).
|
|
281
|
+
- `stat --printf` omits the implicit newline and interprets text escapes, including ASCII
|
|
282
|
+
octal/hex escapes. Numeric escapes producing bytes `0x80`–`0xFF` are rejected before output;
|
|
283
|
+
use literal Unicode text instead. NUL is preserved in direct output, text pipelines, and
|
|
284
|
+
redirected files; command substitution retains fauxnix's existing text behavior rather
|
|
285
|
+
than Bash's NUL-removal behavior.
|
|
253
286
|
- A pipeline producing exactly one line, piped into `wc -l`, counts that line (bash would count 0
|
|
254
287
|
if the producer omitted the trailing newline). `printf 'x' | md5sum` stays byte-exact.
|
|
255
288
|
- `sed`/`awk` support the common subset; hold-space, labels, arrays, loops throw named
|
|
256
289
|
"not supported" errors at translate time.
|
|
290
|
+
For `awk` programs using `printf`, terminal and file-redirect output streams per formatted
|
|
291
|
+
fragment. Pipeline and command-substitution output is coalesced into one text value to
|
|
292
|
+
preserve adjacent fragments without adding separators. That intermediate value requires
|
|
293
|
+
memory proportional to output size and is not capped by the caller's capture budget.
|
|
257
294
|
- `curl`/`wget` refuse loopback/private/reserved addresses (localhost, 127.x, ::1, 10.x,
|
|
258
295
|
172.16–31.x, 192.168.x, 169.254.x) as a safety default for agent-driven HTTP.
|
|
259
296
|
- **Native-tool pipelines vs encoding**: PS 5.1 has a single console-encoding knob, so piping
|
|
@@ -272,10 +309,14 @@ npm run build
|
|
|
272
309
|
npx tsx scratch/run.mjs "any bash command" # quick live check
|
|
273
310
|
```
|
|
274
311
|
|
|
275
|
-
Differential vs Git Bash is opt-in (`FAUXNIX_DIFF_ORACLE=1
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
312
|
+
Differential vs Git Bash is locally opt-in (`FAUXNIX_DIFF_ORACLE=1`). The minimum-runtime
|
|
313
|
+
Windows x64 / PowerShell 5.1 CI lane requires Git Bash and runs the 270-case primary corpus
|
|
314
|
+
plus a separate 41-case supplementary corpus. Other lanes may skip these checks.
|
|
315
|
+
The primary corpus currently matches 269/270 cases (99.6%); the remaining observed mismatch
|
|
316
|
+
is the documented Git Bash empty-regex-alternative behavior. The historical 253-case result
|
|
317
|
+
is not a same-corpus comparison. See [`test/differential/README.md`](test/differential/README.md).
|
|
318
|
+
The primary gate remains at least 200 cases and 95% identity; the weekly oracle also runs
|
|
319
|
+
from `.github/workflows/differential.yml`.
|
|
279
320
|
|
|
280
321
|
Architecture map: `src/parser.ts` (bash subset → AST) · `src/translator.ts` (AST → PowerShell +
|
|
281
322
|
executor wrapper) · `src/executor.ts` (spawn, redirects, session persistence) ·
|
package/dist/cli.js
CHANGED
|
@@ -6,6 +6,7 @@ import { listCommandsJson, registeredNames, specsMarkdown } from './registry.js'
|
|
|
6
6
|
import { encodeCommand } from './encoding.js';
|
|
7
7
|
import { startMcpServer } from './mcp.js';
|
|
8
8
|
import { collectDoctorReport } from './doctor.js';
|
|
9
|
+
import { runFacade } from './facade.js';
|
|
9
10
|
import { runInstall } from './install.js';
|
|
10
11
|
import { packageVersion } from './version.js';
|
|
11
12
|
import { POWERSHELL_ARGS, powerShellDisplay, powerShellMissingMessage, resolvePowerShell, } from './powershell.js';
|
|
@@ -74,6 +75,12 @@ export async function runCli(argv) {
|
|
|
74
75
|
await startMcpServer();
|
|
75
76
|
return;
|
|
76
77
|
}
|
|
78
|
+
if (verb === 'facade') {
|
|
79
|
+
// Experimental bash.exe-compatible entry (RFC: docs/rfc-bash-facade.md).
|
|
80
|
+
// Let pending stdout/stderr writes drain before the process exits.
|
|
81
|
+
process.exitCode = await runFacade(rest);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
77
84
|
if (verb === 'translate') {
|
|
78
85
|
const cmd = rest.join(' ');
|
|
79
86
|
const list = parseCommand(cmd);
|
|
@@ -89,13 +96,17 @@ export async function runCli(argv) {
|
|
|
89
96
|
const list = parseCommand(cmd);
|
|
90
97
|
const plans = translateCommandList(list, EXECUTE_TRANSLATION);
|
|
91
98
|
const session = new FauxnixSession();
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
try {
|
|
100
|
+
const result = await session.run(plans);
|
|
101
|
+
if (result.stdout)
|
|
102
|
+
process.stdout.write(result.stdout);
|
|
103
|
+
if (result.stderr)
|
|
104
|
+
process.stderr.write(result.stderr);
|
|
105
|
+
process.exitCode = result.exitCode;
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
await session.dispose();
|
|
109
|
+
}
|
|
99
110
|
}
|
|
100
111
|
async function runDoctor() {
|
|
101
112
|
const checkOk = await runCheck();
|
package/dist/commands/archive.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { wordToString } from '../ast.js';
|
|
2
|
-
import {
|
|
2
|
+
import { parseWords } from '../registry.js';
|
|
3
3
|
import { argListExpr, exprOfWord, operandExpr } from '../translator.js';
|
|
4
|
+
import { gzipNodeFunctions } from './gzip-node.js';
|
|
4
5
|
/* ------------------------------------------------------------------ */
|
|
5
|
-
/* gzip family — .NET
|
|
6
|
+
/* gzip family — .NET compression and strict Node decoding */
|
|
6
7
|
/* ------------------------------------------------------------------ */
|
|
7
8
|
const PS_GZ_FNS = [
|
|
8
9
|
'Add-Type -AssemblyName System.IO.Compression',
|
|
@@ -28,88 +29,102 @@ const PS_GZ_FNS = [
|
|
|
28
29
|
' $fx_gz.Close()',
|
|
29
30
|
' return ,$fx_ms.ToArray()',
|
|
30
31
|
'}',
|
|
31
|
-
'function fx-gz-
|
|
32
|
-
|
|
33
|
-
'
|
|
32
|
+
'function fx-gz-output-exists($dst) {',
|
|
33
|
+
" [Console]::Error.WriteLine('gzip: ' + $dst + ' already exists; not overwritten')",
|
|
34
|
+
' if ($script:fx_exit -ne 1) { $script:fx_exit = 2 }',
|
|
35
|
+
'}',
|
|
36
|
+
// File compression is no-clobber by default. Ownership begins only after
|
|
37
|
+
// CreateNew succeeds, so a failed open never removes somebody else's file.
|
|
38
|
+
'function fx-gz-write-new($b, $dst) {',
|
|
39
|
+
' $fx_os = $null',
|
|
40
|
+
' $fx_owned = $false',
|
|
34
41
|
' try {',
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
42
|
+
' try {',
|
|
43
|
+
' $fx_os = [IO.File]::Open($dst, [IO.FileMode]::CreateNew, [IO.FileAccess]::Write, [IO.FileShare]::None)',
|
|
44
|
+
' $fx_owned = $true',
|
|
45
|
+
' } catch {',
|
|
46
|
+
// This post-failure check selects a diagnostic; CreateNew enforces the
|
|
47
|
+
// no-overwrite contract even if a destination appears during the operation.
|
|
48
|
+
' if (Test-Path -LiteralPath $dst) { fx-gz-output-exists $dst; return $false }',
|
|
49
|
+
' throw',
|
|
50
|
+
' }',
|
|
51
|
+
' $fx_os.Write($b, 0, $b.Length)',
|
|
52
|
+
' $fx_os.Dispose(); $fx_os = $null',
|
|
53
|
+
' $fx_owned = $false',
|
|
54
|
+
' return $true',
|
|
55
|
+
' } finally {',
|
|
56
|
+
' try { if ($null -ne $fx_os) { $fx_os.Dispose() } }',
|
|
57
|
+
' finally { if ($fx_owned -and [IO.File]::Exists($dst)) { [IO.File]::Delete($dst) } }',
|
|
39
58
|
' }',
|
|
40
59
|
'}',
|
|
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
60
|
'function fx-gz-validate($src, $isBytes) {',
|
|
61
|
+
' fx-gz-decode $src $isBytes ([IO.Stream]::Null) $true',
|
|
62
|
+
' return $true',
|
|
63
|
+
'}',
|
|
64
|
+
'function fx-gz-stream-text($src, $isBytes) {',
|
|
45
65
|
' $fx_gz = fx-gz-open $src $isBytes',
|
|
46
|
-
' $
|
|
47
|
-
' $fx_dec = (New-Object System.Text.UTF8Encoding($false, $true)).GetDecoder()',
|
|
48
|
-
' $fx_utf8 = $true',
|
|
66
|
+
' $fx_sr = $null',
|
|
49
67
|
' try {',
|
|
68
|
+
' $fx_buf = New-Object byte[] 65536',
|
|
69
|
+
' $fx_dec = (New-Object System.Text.UTF8Encoding($false, $true)).GetDecoder()',
|
|
70
|
+
' $fx_utf8 = $true',
|
|
50
71
|
' while ($true) {',
|
|
51
72
|
' $fx_n = $fx_gz.Read($fx_buf, 0, $fx_buf.Length)',
|
|
52
73
|
' if ($fx_n -le 0) { break }',
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
' catch [System.Text.DecoderFallbackException] { $fx_utf8 = $false }',
|
|
56
|
-
' }',
|
|
74
|
+
' try { [void]$fx_dec.GetCharCount($fx_buf, 0, $fx_n, $false) }',
|
|
75
|
+
' catch [System.Text.DecoderFallbackException] { $fx_utf8 = $false; break }',
|
|
57
76
|
' }',
|
|
58
77
|
' if ($fx_utf8) {',
|
|
59
78
|
' try { [void]$fx_dec.GetCharCount($fx_buf, 0, 0, $true) }',
|
|
60
79
|
' catch [System.Text.DecoderFallbackException] { $fx_utf8 = $false }',
|
|
61
80
|
' }',
|
|
62
|
-
'
|
|
63
|
-
'
|
|
64
|
-
' $
|
|
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 {',
|
|
81
|
+
' $fx_gz.Position = 0',
|
|
82
|
+
' if ($fx_utf8) { $fx_enc = New-Object System.Text.UTF8Encoding($false, $true) }',
|
|
83
|
+
' else { try { $fx_enc = [System.Text.Encoding]::GetEncoding(936) } catch { $fx_enc = [System.Text.Encoding]::ASCII } }',
|
|
84
|
+
' $fx_sr = New-Object System.IO.StreamReader($fx_gz, $fx_enc, $false, 65536)',
|
|
74
85
|
' while ($true) {',
|
|
75
86
|
' $fx_line = $fx_sr.ReadLine()',
|
|
76
87
|
' if ($null -eq $fx_line) { break }',
|
|
77
88
|
' Write-Output -NoEnumerate $fx_line',
|
|
78
89
|
' }',
|
|
79
90
|
' } finally {',
|
|
80
|
-
' $fx_sr.Dispose()',
|
|
91
|
+
' if ($null -ne $fx_sr) { $fx_sr.Dispose() } else { $fx_gz.Dispose() }',
|
|
81
92
|
' }',
|
|
82
93
|
'}',
|
|
83
94
|
// File output is streamed into a sibling temporary file. The destination
|
|
84
|
-
//
|
|
85
|
-
//
|
|
95
|
+
// is created only after the stream has been drained. File.Move never
|
|
96
|
+
// overwrites an existing destination, including one that appeared late.
|
|
86
97
|
'function fx-gz-stream-file($src, $dst) {',
|
|
87
98
|
' $fx_full = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($dst)',
|
|
88
99
|
' $fx_parent = [IO.Path]::GetDirectoryName($fx_full)',
|
|
89
100
|
" $fx_tmp = [IO.Path]::Combine($fx_parent, '.fauxnix-gzip-' + [Guid]::NewGuid().ToString('N') + '.tmp')",
|
|
90
|
-
' $fx_gz = $null',
|
|
91
101
|
' $fx_os = $null',
|
|
102
|
+
' $fx_tmpOwned = $false',
|
|
103
|
+
' $fx_outputPhase = $false',
|
|
92
104
|
' try {',
|
|
93
|
-
' $
|
|
94
|
-
|
|
95
|
-
' $
|
|
96
|
-
'
|
|
97
|
-
'
|
|
98
|
-
'
|
|
99
|
-
' $fx_os.Write($fx_buf, 0, $fx_n)',
|
|
100
|
-
' }',
|
|
105
|
+
' $fx_outputPhase = $true',
|
|
106
|
+
' $fx_os = [IO.File]::Open($fx_tmp, [IO.FileMode]::CreateNew, [IO.FileAccess]::Write, [IO.FileShare]::None)',
|
|
107
|
+
' $fx_tmpOwned = $true',
|
|
108
|
+
' $fx_outputPhase = $false',
|
|
109
|
+
' fx-gz-decode $src $false $fx_os $false',
|
|
110
|
+
' $fx_outputPhase = $true',
|
|
101
111
|
' $fx_os.Dispose(); $fx_os = $null',
|
|
102
|
-
'
|
|
103
|
-
'
|
|
104
|
-
' $
|
|
105
|
-
'
|
|
112
|
+
' try { [IO.File]::Move($fx_tmp, $fx_full); $fx_tmpOwned = $false }',
|
|
113
|
+
' catch {',
|
|
114
|
+
' if (Test-Path -LiteralPath $dst) { fx-gz-output-exists $dst; return $false }',
|
|
115
|
+
' throw',
|
|
106
116
|
' }',
|
|
107
|
-
'
|
|
117
|
+
' return $true',
|
|
108
118
|
' } catch {',
|
|
109
|
-
' if ($
|
|
110
|
-
'
|
|
111
|
-
'
|
|
119
|
+
' if ($fx_outputPhase) {',
|
|
120
|
+
" [Console]::Error.WriteLine('gzip: ' + $dst + ': ' + $_.Exception.Message)",
|
|
121
|
+
' $script:fx_exit = 1',
|
|
122
|
+
' return $false',
|
|
123
|
+
' }',
|
|
112
124
|
' throw',
|
|
125
|
+
' } finally {',
|
|
126
|
+
' try { if ($null -ne $fx_os) { $fx_os.Dispose() } }',
|
|
127
|
+
' finally { if ($fx_tmpOwned -and [IO.File]::Exists($fx_tmp)) { [IO.File]::Delete($fx_tmp) } }',
|
|
113
128
|
' }',
|
|
114
129
|
'}',
|
|
115
130
|
].join('\n');
|
|
@@ -153,11 +168,7 @@ function parseGzipArgs(args) {
|
|
|
153
168
|
// other long options (force/quiet/verbose/no-name/recursive...) ignored
|
|
154
169
|
continue;
|
|
155
170
|
}
|
|
156
|
-
if (/^-[1-9]
|
|
157
|
-
p.level = parseInt(t.slice(1), 10);
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (t.startsWith('-') && t.length > 1 && !/^-\d/.test(t)) {
|
|
171
|
+
if (t.startsWith('-') && t.length > 1 && (!/^-\d/.test(t) || /^-[1-9]/.test(t))) {
|
|
161
172
|
for (const c of t.slice(1)) {
|
|
162
173
|
if (c === 'd')
|
|
163
174
|
p.decompress = true;
|
|
@@ -167,6 +178,8 @@ function parseGzipArgs(args) {
|
|
|
167
178
|
p.stdout = true;
|
|
168
179
|
else if (c === 't')
|
|
169
180
|
p.test = true;
|
|
181
|
+
else if (/^[1-9]$/.test(c))
|
|
182
|
+
p.level = Number(c);
|
|
170
183
|
// f/q/v/n/r accepted as no-ops
|
|
171
184
|
}
|
|
172
185
|
continue;
|
|
@@ -202,7 +215,7 @@ function gzBlock(args, ctx, forced) {
|
|
|
202
215
|
' try {',
|
|
203
216
|
p.test ? ' [void](fx-gz-validate $fx_in $true)' : ' fx-gz-stream-text $fx_in $true',
|
|
204
217
|
' } catch {',
|
|
205
|
-
" [Console]::Error.WriteLine('gzip: stdin:
|
|
218
|
+
" [Console]::Error.WriteLine('gzip: stdin: ' + $_.Exception.Message)",
|
|
206
219
|
' $script:fx_exit = 1',
|
|
207
220
|
' }',
|
|
208
221
|
].join('\n')
|
|
@@ -227,29 +240,38 @@ function gzBlock(args, ctx, forced) {
|
|
|
227
240
|
' }',
|
|
228
241
|
];
|
|
229
242
|
if (p.test) {
|
|
230
|
-
fileLoop.push(' try { [void](fx-gz-validate $fx_f $false) }', " catch { [Console]::Error.WriteLine('gzip: ' + $fx_f + ':
|
|
243
|
+
fileLoop.push(' try { [void](fx-gz-validate $fx_f $false) }', " catch { [Console]::Error.WriteLine('gzip: ' + $fx_f + ': ' + $_.Exception.Message); $script:fx_exit = 1 }", ' continue');
|
|
231
244
|
}
|
|
232
245
|
else if (p.decompress) {
|
|
233
|
-
|
|
246
|
+
// Suffixes determine a destination filename only. gunzip -c and zcat
|
|
247
|
+
// validate the stream itself and accept any source filename.
|
|
248
|
+
if (!p.stdout) {
|
|
249
|
+
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')", ' if ($script:fx_exit -ne 1) { $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' }");
|
|
250
|
+
}
|
|
251
|
+
fileLoop.push(' try {', p.stdout
|
|
234
252
|
? ' fx-gz-stream-text $fx_f $false'
|
|
235
253
|
: [
|
|
236
|
-
' fx-gz-stream-file $fx_f $fx_out',
|
|
254
|
+
' if (-not (fx-gz-stream-file $fx_f $fx_out)) { continue }',
|
|
237
255
|
' try { (Get-Item -LiteralPath $fx_out).LastWriteTime = (Get-Item -LiteralPath $fx_f).LastWriteTime } catch {}',
|
|
238
|
-
' if (-not ' + b(p.keep) + ') { Remove-Item -LiteralPath $fx_f -Force }',
|
|
239
|
-
].join('\n'), " } catch { [Console]::Error.WriteLine('gzip: ' + $fx_f + ':
|
|
256
|
+
' if (-not ' + b(p.keep) + ') { Remove-Item -LiteralPath $fx_f -Force -ErrorAction Stop }',
|
|
257
|
+
].join('\n'), " } catch { [Console]::Error.WriteLine('gzip: ' + $fx_f + ': ' + $_.Exception.Message); $script:fx_exit = 1 }");
|
|
240
258
|
}
|
|
241
259
|
else {
|
|
242
|
-
|
|
260
|
+
if (!p.stdout) {
|
|
261
|
+
fileLoop.push(' $fx_low = $fx_f.ToLower()', " if ($fx_low.EndsWith('.gz') -or $fx_low.EndsWith('.tgz')) {", " [Console]::Error.WriteLine('gzip: ' + $fx_f + ': already has .gz suffix -- unchanged')", ' continue', ' }');
|
|
262
|
+
}
|
|
263
|
+
fileLoop.push(' try {', p.stdout
|
|
243
264
|
? ' ' + emitBin('(fx-gz-cbytes ([IO.File]::ReadAllBytes($fx_f)) ' + p.level + ')')
|
|
244
265
|
: [
|
|
245
266
|
' $fx_o = fx-gz-cbytes ([IO.File]::ReadAllBytes($fx_f)) ' + p.level,
|
|
246
|
-
"
|
|
267
|
+
" if (-not (fx-gz-write-new $fx_o ($fx_f + '.gz'))) { continue }",
|
|
247
268
|
" try { (Get-Item -LiteralPath ($fx_f + '.gz')).LastWriteTime = (Get-Item -LiteralPath $fx_f).LastWriteTime } catch {}",
|
|
248
|
-
' if (-not ' + b(p.keep) + ') { Remove-Item -LiteralPath $fx_f -Force }',
|
|
269
|
+
' if (-not ' + b(p.keep) + ') { Remove-Item -LiteralPath $fx_f -Force -ErrorAction Stop }',
|
|
249
270
|
].join('\n'), " } catch { [Console]::Error.WriteLine('gzip: ' + $fx_f + ': ' + $_.Exception.Message); $script:fx_exit = 1 }");
|
|
250
271
|
}
|
|
251
272
|
fileLoop.push(' }');
|
|
252
273
|
return [
|
|
274
|
+
gzipNodeFunctions(ctx.translationMode === 'pure'),
|
|
253
275
|
PS_GZ_FNS,
|
|
254
276
|
'$fx_files = ' + (p.files.length ? argListExpr(p.files, operandExpr) : '@()'),
|
|
255
277
|
'if ($fx_files.Count -eq 0) {',
|
|
@@ -292,38 +314,16 @@ const tar = (args) => {
|
|
|
292
314
|
/* zip / unzip */
|
|
293
315
|
/* ------------------------------------------------------------------ */
|
|
294
316
|
const zip = (args) => {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const rest =
|
|
298
|
-
for (let i = 0; i < raw.length; i++) {
|
|
299
|
-
const t = raw[i];
|
|
300
|
-
if (t === '-x' || t === '--exclude') {
|
|
301
|
-
excludeNote = true;
|
|
302
|
-
if (i + 1 < args.length)
|
|
303
|
-
i++;
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
if (t.startsWith('--exclude=')) {
|
|
307
|
-
excludeNote = true;
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
if (t.startsWith('-') && t.length > 1 && !/^-\d/.test(t))
|
|
311
|
-
continue; // -r -q ... implicit
|
|
312
|
-
rest.push(args[i]);
|
|
313
|
-
}
|
|
314
|
-
const note = excludeNote
|
|
315
|
-
? '[Console]::Error.WriteLine(' +
|
|
316
|
-
psStr('zip: fauxnix: -x/--exclude patterns are not supported, ignoring') +
|
|
317
|
-
')\n'
|
|
318
|
-
: '';
|
|
317
|
+
// CommandSpec has already rejected unsupported options. Keep the same
|
|
318
|
+
// operand boundary as that validation, especially filenames after `--`.
|
|
319
|
+
const { operandWords: rest } = parseWords(args);
|
|
319
320
|
if (rest.length < 2) {
|
|
320
|
-
return (
|
|
321
|
-
"[Console]::Error.WriteLine('zip error: Nothing to do! (fauxnix: usage: zip [-r] ARCHIVE FILES...)'); $script:fx_exit = 12");
|
|
321
|
+
return "[Console]::Error.WriteLine('zip error: Nothing to do! (fauxnix: usage: zip [-r] ARCHIVE FILES...)'); $script:fx_exit = 12";
|
|
322
322
|
}
|
|
323
323
|
const arc = operandExpr(rest[0]);
|
|
324
324
|
const inputs = argListExpr(rest.slice(1), operandExpr);
|
|
325
325
|
return [
|
|
326
|
-
|
|
326
|
+
'$fx_arc = ' + arc,
|
|
327
327
|
'$fx_inputs = ' + inputs,
|
|
328
328
|
'$fx_valid = @()',
|
|
329
329
|
'foreach ($fx_p in $fx_inputs) {',
|
|
@@ -359,11 +359,36 @@ const zip = (args) => {
|
|
|
359
359
|
' }',
|
|
360
360
|
' }',
|
|
361
361
|
' } finally { $fx_z.Dispose() }',
|
|
362
|
-
' if ($fx_rename) { Move-Item -LiteralPath $fx_dst -Destination $fx_arc -Force }',
|
|
362
|
+
' if ($fx_rename) { Move-Item -LiteralPath $fx_dst -Destination $fx_arc -Force -ErrorAction Stop }',
|
|
363
363
|
" } catch { [Console]::Error.WriteLine('zip: fauxnix: ' + $_.Exception.Message); $script:fx_exit = 1 }",
|
|
364
364
|
'}',
|
|
365
365
|
].join('\n');
|
|
366
366
|
};
|
|
367
|
+
/** Remove a literal option prefix without flattening quoted/dynamic values. */
|
|
368
|
+
function afterOptionPrefix(word, length) {
|
|
369
|
+
let remaining = length;
|
|
370
|
+
const strip = (parts) => {
|
|
371
|
+
const result = [];
|
|
372
|
+
for (const part of parts) {
|
|
373
|
+
if (remaining === 0) {
|
|
374
|
+
result.push(part);
|
|
375
|
+
}
|
|
376
|
+
else if (part.kind === 'Text' || part.kind === 'SingleQuoted') {
|
|
377
|
+
const taken = Math.min(remaining, part.text.length);
|
|
378
|
+
remaining -= taken;
|
|
379
|
+
if (taken < part.text.length)
|
|
380
|
+
result.push({ ...part, text: part.text.slice(taken) });
|
|
381
|
+
}
|
|
382
|
+
else if (part.kind === 'DoubleQuoted') {
|
|
383
|
+
const tail = strip(part.parts);
|
|
384
|
+
if (tail.length > 0)
|
|
385
|
+
result.push({ ...part, parts: tail });
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return result;
|
|
389
|
+
};
|
|
390
|
+
return strip(word);
|
|
391
|
+
}
|
|
367
392
|
const unzip = (args) => {
|
|
368
393
|
const raw = args.map(wordToString);
|
|
369
394
|
let list = false;
|
|
@@ -372,14 +397,12 @@ const unzip = (args) => {
|
|
|
372
397
|
const rest = [];
|
|
373
398
|
for (let i = 0; i < raw.length; i++) {
|
|
374
399
|
const t = raw[i];
|
|
375
|
-
if (t === '
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
continue;
|
|
400
|
+
if (t === '--') {
|
|
401
|
+
rest.push(...args.slice(i + 1));
|
|
402
|
+
break;
|
|
379
403
|
}
|
|
380
404
|
if (t.startsWith('--directory=')) {
|
|
381
|
-
|
|
382
|
-
dir = dv;
|
|
405
|
+
dir = afterOptionPrefix(args[i], '--directory='.length);
|
|
383
406
|
continue;
|
|
384
407
|
}
|
|
385
408
|
if (t === '--directory' && i + 1 < args.length) {
|
|
@@ -388,10 +411,19 @@ const unzip = (args) => {
|
|
|
388
411
|
continue;
|
|
389
412
|
}
|
|
390
413
|
if (t.startsWith('-') && t.length > 1 && !/^-\d/.test(t)) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
414
|
+
for (let c = 1; c < t.length; c++) {
|
|
415
|
+
if (t[c] === 'l')
|
|
416
|
+
list = true;
|
|
417
|
+
else if (t[c] === 'o')
|
|
418
|
+
over = true;
|
|
419
|
+
else if (t[c] === 'd') {
|
|
420
|
+
if (c + 1 < t.length)
|
|
421
|
+
dir = afterOptionPrefix(args[i], c + 1);
|
|
422
|
+
else if (i + 1 < args.length)
|
|
423
|
+
dir = args[++i];
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
395
427
|
continue;
|
|
396
428
|
}
|
|
397
429
|
rest.push(args[i]);
|
package/dist/commands/files.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CommandSpec, Handler } from '../registry.js';
|
|
2
2
|
/** Destructive file commands migrated first (#130). Unspec'd handlers stay unchecked.
|
|
3
|
-
* cp
|
|
3
|
+
* cp `-f` is always-on overwrite. mv `-f` retains safe same-volume regular-file
|
|
4
|
+
* replacement and never overrides preservation limits or permissions. */
|
|
4
5
|
export declare const specs: CommandSpec[];
|
|
5
6
|
export declare const handlers: Record<string, Handler>;
|