fauxnix-cli 2.0.0 → 2.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/README.md +17 -5
- package/dist/cli.js +12 -0
- package/dist/commands/files.js +1 -0
- package/dist/commands/gzip-node.d.ts +15 -1
- package/dist/commands/gzip-node.js +25 -8
- package/dist/commands/text-filters.js +10 -7
- package/dist/commands/text-io.js +3 -4
- package/dist/doctor.js +9 -0
- package/dist/facade-launch.d.ts +29 -0
- package/dist/facade-launch.js +197 -0
- package/dist/facade-main.d.ts +1 -0
- package/dist/facade-main.js +11 -0
- package/dist/facade-sea.cjs +17800 -0
- package/dist/facade.js +124 -4
- package/dist/parser.js +24 -32
- package/dist/runtime-support.d.ts +1 -1
- package/dist/runtime-support.js +11 -2
- package/dist/translator.d.ts +1 -0
- package/dist/translator.js +117 -18
- package/dist/version.js +12 -5
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -131,11 +131,23 @@ and preflight semantics.
|
|
|
131
131
|
|
|
132
132
|
### Experimental: native shell facade
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
Point Claude Code's **built-in Bash tool** at fauxnix — no MCP sidecar, zero protocol round
|
|
135
|
+
trips per command:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
fauxnix install --claude-shell # builds a fauxnix-backed bash.exe (~85 MB) and sets
|
|
139
|
+
# CLAUDE_CODE_GIT_BASH_PATH; restart Claude Code after
|
|
140
|
+
fauxnix doctor # reports the launcher status
|
|
141
|
+
fauxnix install --claude-shell-off # restores the previous setting
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The launcher is a copy of your own node.exe with the facade bundle injected via Node SEA
|
|
145
|
+
(experimental trade-off; the GA plan is a small prebuilt stub). It implements the bash argv
|
|
146
|
+
contract (`bash -c`/`-lc`, `$0`/`$1` from trailing operands), adapts the harness's private
|
|
147
|
+
command scaffolding (captured from a live session — payload execution, cwd markers, snapshot
|
|
148
|
+
stubs), and always identifies itself via `--version`. The harness's own Bash approval flow
|
|
149
|
+
governs runs. `fauxnix facade` also runs standalone. Details, security rules, and the protocol
|
|
150
|
+
findings: [RFC — native shell facade](docs/rfc-bash-facade.md).
|
|
139
151
|
|
|
140
152
|
## Measured: your model is probably worse at PowerShell than you think
|
|
141
153
|
|
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ import { encodeCommand } from './encoding.js';
|
|
|
7
7
|
import { startMcpServer } from './mcp.js';
|
|
8
8
|
import { collectDoctorReport } from './doctor.js';
|
|
9
9
|
import { runFacade } from './facade.js';
|
|
10
|
+
import { installClaudeShell, uninstallClaudeShell } from './facade-launch.js';
|
|
10
11
|
import { runInstall } from './install.js';
|
|
11
12
|
import { packageVersion } from './version.js';
|
|
12
13
|
import { POWERSHELL_ARGS, powerShellDisplay, powerShellMissingMessage, resolvePowerShell, } from './powershell.js';
|
|
@@ -64,6 +65,17 @@ export async function runCli(argv) {
|
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
67
|
if (verb === 'install') {
|
|
68
|
+
if (rest.includes('--claude-shell')) {
|
|
69
|
+
// Experimental: bash.exe facade launcher (RFC: docs/rfc-bash-facade.md)
|
|
70
|
+
for (const line of await installClaudeShell())
|
|
71
|
+
console.log(line);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (rest.includes('--claude-shell-off')) {
|
|
75
|
+
for (const line of await uninstallClaudeShell())
|
|
76
|
+
console.log(line);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
67
79
|
const result = runInstall(rest);
|
|
68
80
|
for (const line of result.lines)
|
|
69
81
|
console.log(line);
|
package/dist/commands/files.js
CHANGED
|
@@ -71,6 +71,7 @@ const ls = (args) => {
|
|
|
71
71
|
return [
|
|
72
72
|
PS_GLOB_FN,
|
|
73
73
|
PS_FTIME_FN,
|
|
74
|
+
PS_HSIZE_FN,
|
|
74
75
|
'function fx-mode($it) {',
|
|
75
76
|
" $t = '-'; if ($it.PSIsContainer) { $t = 'd' } elseif " + psIsLink('$it') + " { $t = 'l' }",
|
|
76
77
|
" if ($it.PSIsContainer) { return ($t + 'rwxr-xr-x') }",
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Trusted program, no user text interpolation. It only reads input and emits bytes.
|
|
3
|
+
*
|
|
4
|
+
* A leased stdin is an ownership signal, not archive data or host RPC. PowerShell
|
|
5
|
+
* holds it open; EOF/error aborts decoding. The parent PID check is best effort.
|
|
6
|
+
*
|
|
7
|
+
* Windows pipe stdout writes are synchronous and can block the event loop that
|
|
8
|
+
* observes ownership loss. Its fs writer instead keeps those writes off-thread.
|
|
9
|
+
* An abandoned write can still retain a libuv worker during process.exit cleanup,
|
|
10
|
+
* so the existing one-second shutdown fallback directly terminates this Windows
|
|
11
|
+
* helper (exit code 1). POSIX retains its asynchronous stdout socket and exit path.
|
|
12
|
+
*
|
|
13
|
+
* Keep commentary outside the embedded program: its base64 is nested inside
|
|
14
|
+
* generated PowerShell, where avoidable size can exceed Windows argv limits.
|
|
15
|
+
*/
|
|
2
16
|
export declare const GZIP_DECODER_SOURCE: string;
|
|
3
17
|
export declare function gzipNodeFunctions(pure: boolean): string;
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { psStr } from '../registry.js';
|
|
2
2
|
import { nodeEngineRange } from '../runtime-support.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Trusted program, no user text interpolation. It only reads input and emits bytes.
|
|
5
|
+
*
|
|
6
|
+
* A leased stdin is an ownership signal, not archive data or host RPC. PowerShell
|
|
7
|
+
* holds it open; EOF/error aborts decoding. The parent PID check is best effort.
|
|
8
|
+
*
|
|
9
|
+
* Windows pipe stdout writes are synchronous and can block the event loop that
|
|
10
|
+
* observes ownership loss. Its fs writer instead keeps those writes off-thread.
|
|
11
|
+
* An abandoned write can still retain a libuv worker during process.exit cleanup,
|
|
12
|
+
* so the existing one-second shutdown fallback directly terminates this Windows
|
|
13
|
+
* helper (exit code 1). POSIX retains its asynchronous stdout socket and exit path.
|
|
14
|
+
*
|
|
15
|
+
* Keep commentary outside the embedded program: its base64 is nested inside
|
|
16
|
+
* generated PowerShell, where avoidable size can exceed Windows argv limits.
|
|
17
|
+
*/
|
|
4
18
|
export const GZIP_DECODER_SOURCE = String.raw `
|
|
5
|
-
const { createReadStream } = require('node:fs');
|
|
19
|
+
const { createReadStream, createWriteStream } = require('node:fs');
|
|
6
20
|
const { createGunzip } = require('node:zlib');
|
|
7
21
|
const { Writable } = require('node:stream');
|
|
8
22
|
const { pipeline } = require('node:stream/promises');
|
|
@@ -14,14 +28,13 @@ const { pipeline } = require('node:stream/promises');
|
|
|
14
28
|
if (finished || stopping) return;
|
|
15
29
|
stopping = true;
|
|
16
30
|
controller.abort();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
if (process.platform === 'win32') process.kill(process.pid, 'SIGTERM');
|
|
33
|
+
else process.exit(1);
|
|
34
|
+
}, 1000).unref();
|
|
20
35
|
};
|
|
21
36
|
const leased = process.argv[4] === 'lease';
|
|
22
37
|
if (leased) {
|
|
23
|
-
// PowerShell keeps this private input pipe open without writing to it.
|
|
24
|
-
// EOF is an ownership signal, not compressed input or a host RPC message.
|
|
25
38
|
process.stdin.on('end', stopDecoder);
|
|
26
39
|
process.stdin.on('error', stopDecoder);
|
|
27
40
|
process.stdin.resume();
|
|
@@ -49,7 +62,11 @@ const { pipeline } = require('node:stream/promises');
|
|
|
49
62
|
const path = Buffer.from(process.argv[1], 'base64').toString('utf8');
|
|
50
63
|
const mode = process.argv[2];
|
|
51
64
|
if (mode !== 'test' && mode !== 'stream') throw new Error('invalid decoder mode');
|
|
52
|
-
const sink = mode === 'test'
|
|
65
|
+
const sink = mode === 'test'
|
|
66
|
+
? new Writable({ write(chunk, encoding, next) { next(); } })
|
|
67
|
+
: process.platform === 'win32'
|
|
68
|
+
? createWriteStream(null, { fd: 1, autoClose: false })
|
|
69
|
+
: process.stdout;
|
|
53
70
|
await pipeline(createReadStream(path), createGunzip(), sink, { signal: controller.signal });
|
|
54
71
|
} catch (error) {
|
|
55
72
|
process.stderr.write('gzip decoder: ' + String(error.message).slice(0, 2048) + '\n');
|
|
@@ -2206,17 +2206,20 @@ const uniq = (args) => {
|
|
|
2206
2206
|
}
|
|
2207
2207
|
lines.push('}');
|
|
2208
2208
|
lines.push('function fx-uemit($l, $c) {');
|
|
2209
|
-
|
|
2210
|
-
|
|
2209
|
+
// Selection and formatting are independent: -cd/-cu retain counts,
|
|
2210
|
+
// while -du selects no groups regardless of option order.
|
|
2211
|
+
const emit = count ? "$fx_res.Add(('{0,7} {1}' -f $c, $l))" : '$fx_res.Add($l)';
|
|
2212
|
+
if (dupOnly && uniqOnly) {
|
|
2213
|
+
lines.push(' return');
|
|
2211
2214
|
}
|
|
2212
|
-
else if (
|
|
2213
|
-
lines.push(' if ($c -
|
|
2215
|
+
else if (dupOnly) {
|
|
2216
|
+
lines.push(' if ($c -gt 1) { ' + emit + ' }');
|
|
2214
2217
|
}
|
|
2215
|
-
else if (
|
|
2216
|
-
lines.push(
|
|
2218
|
+
else if (uniqOnly) {
|
|
2219
|
+
lines.push(' if ($c -eq 1) { ' + emit + ' }');
|
|
2217
2220
|
}
|
|
2218
2221
|
else {
|
|
2219
|
-
lines.push('
|
|
2222
|
+
lines.push(' ' + emit);
|
|
2220
2223
|
}
|
|
2221
2224
|
lines.push('}');
|
|
2222
2225
|
lines.push('$fx_res = New-Object System.Collections.Generic.List[string]');
|
package/dist/commands/text-io.js
CHANGED
|
@@ -859,12 +859,11 @@ const tac = (args) => {
|
|
|
859
859
|
PS_SPLITLINES_FN,
|
|
860
860
|
STDIN_INLINES,
|
|
861
861
|
...psCollectFiles(operandWords, (g) => qErr('tac', g, 'No such file or directory', 'failed to open '), (g) => sErr('tac', g, 'read error: Is a directory')),
|
|
862
|
-
'$fx_all = @()',
|
|
863
862
|
'foreach ($fx_g in $fx_srcs) {',
|
|
864
|
-
" if ($fx_g -eq '-') { $
|
|
865
|
-
' else { $
|
|
863
|
+
" if ($fx_g -eq '-') { $fx_ls = @($fx_in) }",
|
|
864
|
+
' else { $fx_ls = @(fx-splitlines (fx-read $fx_g)) }',
|
|
865
|
+
' for ($fx_i = $fx_ls.Count - 1; $fx_i -ge 0; $fx_i--) { $fx_ls[$fx_i] }',
|
|
866
866
|
'}',
|
|
867
|
-
'for ($fx_i = $fx_all.Count - 1; $fx_i -ge 0; $fx_i--) { $fx_all[$fx_i] }',
|
|
868
867
|
].join('\n');
|
|
869
868
|
};
|
|
870
869
|
/* ------------------------------------------------------------------ */
|
package/dist/doctor.js
CHANGED
|
@@ -3,6 +3,7 @@ import { nodeEngineRange, supportsNode } from './runtime-support.js';
|
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { resolveQwenLaunchTuple, sameQwenLaunchTuple } from './qwen-launch.js';
|
|
6
|
+
import { launcherStatus } from './facade-launch.js';
|
|
6
7
|
const VALUE_INDENT = ' ';
|
|
7
8
|
export async function collectDoctorReport(opts = {}) {
|
|
8
9
|
const home = opts.home ?? homedir();
|
|
@@ -16,6 +17,7 @@ export async function collectDoctorReport(opts = {}) {
|
|
|
16
17
|
lines.push(field('codex', detectCodex(home, env)));
|
|
17
18
|
lines.push(field('opencode', detectOpenCode(home, env)));
|
|
18
19
|
lines.push(field('qwen', detectQwen(home)));
|
|
20
|
+
lines.push(field('facade', detectFacade(env)));
|
|
19
21
|
lines.push('');
|
|
20
22
|
const mcp = await mcpLines(nodeVersion, opts.loadMcp);
|
|
21
23
|
lines.push(...mcp.lines);
|
|
@@ -24,6 +26,13 @@ export async function collectDoctorReport(opts = {}) {
|
|
|
24
26
|
function field(label, value) {
|
|
25
27
|
return `${label.padEnd(10)} : ${value}`;
|
|
26
28
|
}
|
|
29
|
+
function detectFacade(env) {
|
|
30
|
+
const status = launcherStatus(env);
|
|
31
|
+
const pointed = env['CLAUDE_CODE_GIT_BASH_PATH'] === status.exePath ? ', CLAUDE_CODE_GIT_BASH_PATH points at it' : '';
|
|
32
|
+
if (!status.installed)
|
|
33
|
+
return 'not installed (experimental: fauxnix install --claude-shell)';
|
|
34
|
+
return `${status.upToDate ? 'up to date' : 'stale'} at ${status.exePath}${pointed}`;
|
|
35
|
+
}
|
|
27
36
|
function encodingLines(env) {
|
|
28
37
|
const raw = env.FAUXNIX_NATIVE_ENCODING;
|
|
29
38
|
const current = raw === undefined || raw === ''
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Experimental bash.exe launcher (RFC: docs/rfc-bash-facade.md).
|
|
3
|
+
*
|
|
4
|
+
* Harnesses point CLAUDE_CODE_GIT_BASH_PATH at an executable whose basename
|
|
5
|
+
* is exactly bash.exe, so the launcher is a copy of the active node.exe with
|
|
6
|
+
* the prebuilt facade bundle (dist/facade-sea.cjs) injected via Node SEA +
|
|
7
|
+
* postject. Roughly 85 MB per install — the documented experimental-phase
|
|
8
|
+
* trade; the GA plan is a small prebuilt stub.
|
|
9
|
+
*/
|
|
10
|
+
export interface LauncherStatus {
|
|
11
|
+
/** Directory that holds (or would hold) bash.exe. */
|
|
12
|
+
dir: string;
|
|
13
|
+
exePath: string;
|
|
14
|
+
installed: boolean;
|
|
15
|
+
upToDate: boolean;
|
|
16
|
+
packageVersion: string;
|
|
17
|
+
nodeVersion: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function launcherDir(env?: NodeJS.ProcessEnv): string;
|
|
20
|
+
export declare function launcherStatus(env?: NodeJS.ProcessEnv): LauncherStatus;
|
|
21
|
+
/** Build (or rebuild when stale) the launcher; returns the bash.exe path. */
|
|
22
|
+
export declare function buildLauncher(env?: NodeJS.ProcessEnv): Promise<string>;
|
|
23
|
+
/** User-level CLAUDE_CODE_GIT_BASH_PATH management, with prior-value restore. */
|
|
24
|
+
export declare function setUserEnv(name: string, value: string | null): Promise<void>;
|
|
25
|
+
export declare function getUserEnv(name: string): Promise<string | null>;
|
|
26
|
+
/** `fauxnix install --claude-shell` — build the launcher and point Claude Code at it. */
|
|
27
|
+
export declare function installClaudeShell(env?: NodeJS.ProcessEnv): Promise<string[]>;
|
|
28
|
+
/** `fauxnix install --claude-shell-off` — restore the previous value and remove the launcher. */
|
|
29
|
+
export declare function uninstallClaudeShell(env?: NodeJS.ProcessEnv): Promise<string[]>;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { copyFileSync, existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
import { inject as postjectInject } from 'postject';
|
|
8
|
+
import { packageVersion } from './version.js';
|
|
9
|
+
const execFileAsync = promisify(execFile);
|
|
10
|
+
export function launcherDir(env = process.env) {
|
|
11
|
+
const override = env['FAUXNIX_FACADE_DIR'];
|
|
12
|
+
if (override)
|
|
13
|
+
return override;
|
|
14
|
+
const base = env['LOCALAPPDATA'] ?? env['USERPROFILE'] ?? '.';
|
|
15
|
+
return join(base, 'fauxnix', 'bin');
|
|
16
|
+
}
|
|
17
|
+
function markerPath(dir) {
|
|
18
|
+
return join(dir, 'bash.exe.launcher.json');
|
|
19
|
+
}
|
|
20
|
+
function launcherInputs(env) {
|
|
21
|
+
// src/ and dist/ are both one level below the package root.
|
|
22
|
+
const bundle = new URL('../dist/facade-sea.cjs', import.meta.url);
|
|
23
|
+
if (!existsSync(bundle)) {
|
|
24
|
+
throw new Error('fauxnix: dist/facade-sea.cjs is missing — run npm run build first');
|
|
25
|
+
}
|
|
26
|
+
const stubPath = env['FAUXNIX_FACADE_STUB'] ? resolve(env['FAUXNIX_FACADE_STUB']) : null;
|
|
27
|
+
if (stubPath && !existsSync(stubPath)) {
|
|
28
|
+
throw new Error(`fauxnix: FAUXNIX_FACADE_STUB does not exist: ${stubPath}`);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
formatVersion: 1,
|
|
32
|
+
packageVersion,
|
|
33
|
+
nodeVersion: process.version,
|
|
34
|
+
mode: stubPath ? 'stub' : 'sea',
|
|
35
|
+
nodePath: process.execPath,
|
|
36
|
+
bundlePath: fileURLToPath(bundle),
|
|
37
|
+
bundleHash: createHash('sha256').update(readFileSync(bundle)).digest('hex'),
|
|
38
|
+
stubPath,
|
|
39
|
+
stubHash: stubPath ? createHash('sha256').update(readFileSync(stubPath)).digest('hex') : null,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function readMarker(dir) {
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(readFileSync(markerPath(dir), 'utf8'));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function launcherMatches(dir, inputs) {
|
|
51
|
+
const marker = readMarker(dir);
|
|
52
|
+
// Version-only markers predate input tracking and must be rebuilt once.
|
|
53
|
+
if (!Object.entries(inputs).every(([key, value]) => marker?.[key] === value))
|
|
54
|
+
return false;
|
|
55
|
+
if (inputs.mode === 'sea')
|
|
56
|
+
return true;
|
|
57
|
+
try {
|
|
58
|
+
const routing = JSON.parse(readFileSync(join(dir, 'fauxnix-launch.json'), 'utf8'));
|
|
59
|
+
return routing?.node === inputs.nodePath && routing?.bundle === inputs.bundlePath;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function launcherStatus(env = process.env) {
|
|
66
|
+
const dir = launcherDir(env);
|
|
67
|
+
const exePath = join(dir, 'bash.exe');
|
|
68
|
+
const installed = existsSync(exePath);
|
|
69
|
+
let upToDate = false;
|
|
70
|
+
try {
|
|
71
|
+
upToDate = installed && launcherMatches(dir, launcherInputs(env));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Doctor reports stale for missing/unreadable inputs; buildLauncher gives
|
|
75
|
+
// the actionable error rather than silently reusing or changing modes.
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
dir,
|
|
79
|
+
exePath,
|
|
80
|
+
installed,
|
|
81
|
+
upToDate,
|
|
82
|
+
packageVersion,
|
|
83
|
+
nodeVersion: process.version,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** Build (or rebuild when stale) the launcher; returns the bash.exe path. */
|
|
87
|
+
export async function buildLauncher(env = process.env) {
|
|
88
|
+
const dir = launcherDir(env);
|
|
89
|
+
const exePath = join(dir, 'bash.exe');
|
|
90
|
+
const inputs = launcherInputs(env);
|
|
91
|
+
if (existsSync(exePath) && launcherMatches(dir, inputs))
|
|
92
|
+
return exePath;
|
|
93
|
+
const { mkdirSync } = await import('node:fs');
|
|
94
|
+
mkdirSync(dir, { recursive: true });
|
|
95
|
+
// A failed rebuild can replace bash.exe. Never leave the previous marker
|
|
96
|
+
// claiming that partially replaced launcher is still current.
|
|
97
|
+
rmSync(markerPath(dir), { force: true });
|
|
98
|
+
// GA path (RFC #224 Option B): a small prebuilt stub that forwards argv to
|
|
99
|
+
// this installation's node + bundle. Its build/signing pipeline is tracked
|
|
100
|
+
// separately; when FAUXNIX_FACADE_STUB points at a stub binary, install it
|
|
101
|
+
// with a routing config instead of the ~85 MB SEA copy.
|
|
102
|
+
if (inputs.stubPath) {
|
|
103
|
+
rmSync(exePath, { force: true });
|
|
104
|
+
copyFileSync(inputs.stubPath, exePath);
|
|
105
|
+
writeFileSync(join(dir, 'fauxnix-launch.json'), JSON.stringify({ node: inputs.nodePath, bundle: inputs.bundlePath }, null, 2));
|
|
106
|
+
writeFileSync(markerPath(dir), JSON.stringify(inputs));
|
|
107
|
+
return exePath;
|
|
108
|
+
}
|
|
109
|
+
const configPath = join(dir, 'sea-config.json');
|
|
110
|
+
const blobPath = join(dir, 'sea-prep.blob');
|
|
111
|
+
writeFileSync(configPath, JSON.stringify({
|
|
112
|
+
main: inputs.bundlePath,
|
|
113
|
+
output: blobPath,
|
|
114
|
+
disableExperimentalSEAWarning: true,
|
|
115
|
+
}));
|
|
116
|
+
try {
|
|
117
|
+
await execFileAsync(inputs.nodePath, ['--experimental-sea-config', configPath]);
|
|
118
|
+
rmSync(exePath, { force: true });
|
|
119
|
+
copyFileSync(inputs.nodePath, exePath);
|
|
120
|
+
// postject rewrites the PE resource section; any original Authenticode
|
|
121
|
+
// signature is invalidated, which is expected for a local build.
|
|
122
|
+
await postjectInject(exePath, 'NODE_SEA_BLOB', readFileSync(blobPath), {
|
|
123
|
+
sentinelFuse: 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
rmSync(configPath, { force: true });
|
|
128
|
+
rmSync(blobPath, { force: true });
|
|
129
|
+
}
|
|
130
|
+
writeFileSync(markerPath(dir), JSON.stringify(inputs));
|
|
131
|
+
return exePath;
|
|
132
|
+
}
|
|
133
|
+
/** User-level CLAUDE_CODE_GIT_BASH_PATH management, with prior-value restore. */
|
|
134
|
+
export async function setUserEnv(name, value) {
|
|
135
|
+
const ps = value === null
|
|
136
|
+
? `[Environment]::SetEnvironmentVariable('${name}', $null, 'User')`
|
|
137
|
+
: `[Environment]::SetEnvironmentVariable('${name}', ${JSON.stringify(value)}, 'User')`;
|
|
138
|
+
await execFileAsync('powershell.exe', ['-NoProfile', '-Command', ps]);
|
|
139
|
+
}
|
|
140
|
+
export async function getUserEnv(name) {
|
|
141
|
+
try {
|
|
142
|
+
const { stdout } = await execFileAsync('powershell.exe', [
|
|
143
|
+
'-NoProfile',
|
|
144
|
+
'-Command',
|
|
145
|
+
`[Environment]::GetEnvironmentVariable('${name}', 'User')`,
|
|
146
|
+
]);
|
|
147
|
+
const v = stdout.trim();
|
|
148
|
+
return v === '' ? null : v;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const SHELL_ENV = 'CLAUDE_CODE_GIT_BASH_PATH';
|
|
155
|
+
const PREVIOUS_FILE = 'claude-shell.previous.txt';
|
|
156
|
+
function previousPath(dir) {
|
|
157
|
+
return join(dir, PREVIOUS_FILE);
|
|
158
|
+
}
|
|
159
|
+
/** `fauxnix install --claude-shell` — build the launcher and point Claude Code at it. */
|
|
160
|
+
export async function installClaudeShell(env = process.env) {
|
|
161
|
+
const lines = [];
|
|
162
|
+
const exePath = await buildLauncher(env);
|
|
163
|
+
lines.push(`launcher ready: ${exePath}`);
|
|
164
|
+
const prev = await getUserEnv(SHELL_ENV);
|
|
165
|
+
if (prev && prev !== exePath) {
|
|
166
|
+
const dir = launcherDir(env);
|
|
167
|
+
if (!existsSync(previousPath(dir))) {
|
|
168
|
+
writeFileSync(previousPath(dir), prev, 'utf8');
|
|
169
|
+
lines.push(`saved previous ${SHELL_ENV}: ${prev}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
await setUserEnv(SHELL_ENV, exePath);
|
|
173
|
+
lines.push(`set user ${SHELL_ENV}=${exePath}`);
|
|
174
|
+
lines.push('restart Claude Code from a new terminal to pick it up');
|
|
175
|
+
lines.push('note: the harness approval flow for its built-in Bash tool now governs fauxnix runs');
|
|
176
|
+
lines.push('undo anytime with: fauxnix install --claude-shell-off');
|
|
177
|
+
return lines;
|
|
178
|
+
}
|
|
179
|
+
/** `fauxnix install --claude-shell-off` — restore the previous value and remove the launcher. */
|
|
180
|
+
export async function uninstallClaudeShell(env = process.env) {
|
|
181
|
+
const lines = [];
|
|
182
|
+
const dir = launcherDir(env);
|
|
183
|
+
let prev = null;
|
|
184
|
+
try {
|
|
185
|
+
prev = readFileSync(previousPath(dir), 'utf8').trim() || null;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
/* no saved previous value */
|
|
189
|
+
}
|
|
190
|
+
await setUserEnv(SHELL_ENV, prev);
|
|
191
|
+
lines.push(prev ? `restored ${SHELL_ENV}=${prev}` : `removed user ${SHELL_ENV}`);
|
|
192
|
+
rmSync(join(dir, 'bash.exe'), { force: true });
|
|
193
|
+
rmSync(markerPath(dir), { force: true });
|
|
194
|
+
rmSync(previousPath(dir), { force: true });
|
|
195
|
+
lines.push(`removed launcher: ${join(dir, 'bash.exe')}`);
|
|
196
|
+
return lines;
|
|
197
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './commands/install-all.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Self-contained entry for the experimental bash.exe launcher (RFC #224).
|
|
2
|
+
// The launcher build bundles this file with esbuild into a single CJS blob,
|
|
3
|
+
// injected into a copy of node.exe named bash.exe via Node SEA + postject.
|
|
4
|
+
// Claude Code then spawns `bash.exe -c "<cmd>"` / keeps a persistent stdin
|
|
5
|
+
// session — argv contract is handled by runFacade.
|
|
6
|
+
import './commands/install-all.js';
|
|
7
|
+
import { runFacade } from './facade.js';
|
|
8
|
+
void (async () => {
|
|
9
|
+
const code = await runFacade(process.argv.slice(2));
|
|
10
|
+
process.exit(code);
|
|
11
|
+
})();
|