fauxnix-cli 2.1.0 → 2.2.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 +20 -9
- package/dist/cli.js +25 -3
- package/dist/commands/archive.js +100 -2
- package/dist/commands/files.d.ts +8 -0
- package/dist/commands/files.js +131 -19
- package/dist/commands/gzip-node.js +4 -0
- package/dist/commands/text-filters.js +102 -19
- package/dist/commands/text-io.js +11 -4
- package/dist/doctor.js +35 -0
- package/dist/executor.d.ts +39 -2
- package/dist/executor.js +150 -13
- package/dist/facade-sea.cjs +518 -86
- package/dist/facade.js +6 -2
- package/dist/install.js +87 -44
- package/dist/mcp-launch.d.ts +22 -0
- package/dist/mcp-launch.js +44 -0
- package/dist/mcp.js +8 -2
- package/dist/parser.js +15 -0
- package/dist/ps-host.d.ts +5 -0
- package/dist/ps-host.js +47 -23
- package/dist/qwen-launch.d.ts +5 -12
- package/dist/qwen-launch.js +5 -29
- package/dist/translator.d.ts +9 -0
- package/dist/translator.js +73 -2
- package/package.json +67 -67
package/dist/facade.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appendFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { parseCommand } from './parser.js';
|
|
3
3
|
import { translateCommandList, EXECUTE_TRANSLATION } from './translator.js';
|
|
4
|
-
import { FauxnixSession } from './executor.js';
|
|
4
|
+
import { FauxnixSession, installSessionExitCleanup } from './executor.js';
|
|
5
5
|
import { packageVersion } from './version.js';
|
|
6
6
|
/**
|
|
7
7
|
* Experimental native-shell facade (RFC: docs/rfc-bash-facade.md).
|
|
@@ -202,9 +202,13 @@ function parseDashC(argv) {
|
|
|
202
202
|
}
|
|
203
203
|
export async function runFacade(argv) {
|
|
204
204
|
trace('argv', argv.join(' '));
|
|
205
|
+
installSessionExitCleanup();
|
|
205
206
|
const session = new FauxnixSession();
|
|
206
207
|
try {
|
|
207
|
-
|
|
208
|
+
// GNU bash answers --version wherever it appears among the options
|
|
209
|
+
// (`bash -l --version`), not only as argv[0] (#259). Exact element match:
|
|
210
|
+
// a script operand containing the text is data, not an option.
|
|
211
|
+
if (argv.some((a) => a === '--version')) {
|
|
208
212
|
process.stdout.write(VERSION_LINE);
|
|
209
213
|
return 0;
|
|
210
214
|
}
|
package/dist/install.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
|
-
import { claudeUserConfigPath, codexConfigPath, fauxnixServerNames, hasCodexFauxnix,
|
|
5
|
-
import {
|
|
4
|
+
import { claudeUserConfigPath, codexConfigPath, fauxnixServerNames, hasCodexFauxnix, isServerMap, openCodeConfigPath, } from './doctor.js';
|
|
5
|
+
import { isLegacyFauxnixCommand, resolveMcpLaunchTuple, sameMcpLaunchTuple, } from './mcp-launch.js';
|
|
6
6
|
export const INSTALL_FLAGS = ['claude', 'codex', 'opencode', 'kimi', 'qwen'];
|
|
7
|
-
const STDIO = { command: 'fauxnix', args: ['mcp'] };
|
|
8
|
-
const OPENCODE_STDIO = { type: 'local', command: ['fauxnix', 'mcp'] };
|
|
9
7
|
export function kimiConfigPath(home, env) {
|
|
10
8
|
const root = env.KIMI_CODE_HOME?.trim() || join(home, '.kimi-code');
|
|
11
9
|
return join(root, 'mcp.json');
|
|
@@ -19,6 +17,12 @@ export function runInstall(argv, opts = {}) {
|
|
|
19
17
|
return { lines: installUsageLines(), ok: true };
|
|
20
18
|
if (parsed.error)
|
|
21
19
|
return { lines: [parsed.error, ...installUsageLines()], ok: false };
|
|
20
|
+
// Every harness config carries the spawn-safe absolute launcher (#252):
|
|
21
|
+
// resolve it once; a failure to locate Node or the built entry fails the
|
|
22
|
+
// whole run rather than writing a config that cannot start.
|
|
23
|
+
const launch = resolveMcpLaunchTuple();
|
|
24
|
+
if (!launch.ok)
|
|
25
|
+
return { lines: [launch.reason], ok: false };
|
|
22
26
|
const ctx = {
|
|
23
27
|
home: opts.home ?? homedir(),
|
|
24
28
|
env: opts.env ?? process.env,
|
|
@@ -26,7 +30,7 @@ export function runInstall(argv, opts = {}) {
|
|
|
26
30
|
const lines = [];
|
|
27
31
|
let ok = true;
|
|
28
32
|
for (const name of parsed.harnesses) {
|
|
29
|
-
const one = installHarness(name, ctx);
|
|
33
|
+
const one = installHarness(name, ctx, launch.value);
|
|
30
34
|
lines.push(one.line);
|
|
31
35
|
if (!one.ok)
|
|
32
36
|
ok = false;
|
|
@@ -61,24 +65,21 @@ function isHarness(s) {
|
|
|
61
65
|
function installUsageLines() {
|
|
62
66
|
return ['Usage:', ' fauxnix install --claude|--codex|--opencode|--kimi|--qwen'];
|
|
63
67
|
}
|
|
64
|
-
function installHarness(name, ctx) {
|
|
68
|
+
function installHarness(name, ctx, launch) {
|
|
65
69
|
switch (name) {
|
|
66
70
|
case 'claude':
|
|
67
|
-
return patchMcpServers(claudeUserConfigPath(ctx.home, ctx.env), 'claude');
|
|
71
|
+
return patchMcpServers(claudeUserConfigPath(ctx.home, ctx.env), 'claude', launch);
|
|
68
72
|
case 'codex':
|
|
69
|
-
return patchCodex(codexConfigPath(ctx.home, ctx.env));
|
|
73
|
+
return patchCodex(codexConfigPath(ctx.home, ctx.env), launch);
|
|
70
74
|
case 'opencode':
|
|
71
|
-
return patchOpenCode(openCodeConfigPath(ctx.home, ctx.env));
|
|
75
|
+
return patchOpenCode(openCodeConfigPath(ctx.home, ctx.env), launch);
|
|
72
76
|
case 'kimi':
|
|
73
|
-
return patchMcpServers(kimiConfigPath(ctx.home, ctx.env), 'kimi');
|
|
77
|
+
return patchMcpServers(kimiConfigPath(ctx.home, ctx.env), 'kimi', launch);
|
|
74
78
|
case 'qwen':
|
|
75
|
-
return patchQwen(qwenConfigPath(ctx.home, ctx.env));
|
|
79
|
+
return patchQwen(qwenConfigPath(ctx.home, ctx.env), launch);
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
|
-
function patchQwen(path) {
|
|
79
|
-
const launch = resolveQwenLaunchTuple();
|
|
80
|
-
if (!launch.ok)
|
|
81
|
-
return { ok: false, line: `qwen: ${launch.reason} — not modified` };
|
|
82
|
+
function patchQwen(path, launch) {
|
|
82
83
|
const read = readJsonObject(path);
|
|
83
84
|
if (read.state === 'invalid') {
|
|
84
85
|
return { ok: false, line: `qwen: ${path} is ${read.reason} — not modified` };
|
|
@@ -105,65 +106,80 @@ function patchQwen(path) {
|
|
|
105
106
|
line: `qwen: ${path} mcpServers.fauxnix is not an object — not modified`,
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
|
-
if (
|
|
109
|
+
if (sameMcpLaunchTuple(current, launch)) {
|
|
109
110
|
return { ok: true, line: `qwen: already configured with an absolute launcher (${path})` };
|
|
110
111
|
}
|
|
112
|
+
if (current != null && !isLegacyFauxnixCommand(current)) {
|
|
113
|
+
// A hand-written launcher the user chose deliberately; leave it alone.
|
|
114
|
+
return { ok: true, line: `qwen: already configured (${path})` };
|
|
115
|
+
}
|
|
111
116
|
servers.fauxnix = {
|
|
112
117
|
...(isServerMap(current) ? current : {}),
|
|
113
|
-
command: launch.
|
|
114
|
-
args: [...launch.
|
|
118
|
+
command: launch.command,
|
|
119
|
+
args: [...launch.args],
|
|
115
120
|
};
|
|
116
|
-
return writeJson(path, data, 'qwen', existed, current == null ? 'added mcpServers.fauxnix' : '
|
|
121
|
+
return writeJson(path, data, 'qwen', existed, current == null ? 'added mcpServers.fauxnix' : 'upgraded mcpServers.fauxnix to the absolute launcher');
|
|
117
122
|
}
|
|
118
|
-
function patchMcpServers(path, harness) {
|
|
123
|
+
function patchMcpServers(path, harness, launch) {
|
|
119
124
|
const read = readJsonObject(path);
|
|
120
125
|
if (read.state === 'invalid') {
|
|
121
126
|
return { ok: false, line: `${harness}: ${path} is ${read.reason} — not modified` };
|
|
122
127
|
}
|
|
123
128
|
const existed = read.state !== 'missing';
|
|
124
129
|
const data = read.state === 'ok' ? read.data : {};
|
|
125
|
-
if (serverMapHasFauxnix(data.mcpServers)) {
|
|
126
|
-
return { ok: true, line: `${harness}: already configured (${path})` };
|
|
127
|
-
}
|
|
128
130
|
if (data.mcpServers != null && !isServerMap(data.mcpServers)) {
|
|
129
131
|
return { ok: false, line: `${harness}: ${path} mcpServers is not an object — not modified` };
|
|
130
132
|
}
|
|
131
133
|
if (!isServerMap(data.mcpServers))
|
|
132
134
|
data.mcpServers = {};
|
|
133
|
-
data.mcpServers
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
const servers = data.mcpServers;
|
|
136
|
+
const current = servers.fauxnix;
|
|
137
|
+
if (current != null && !isServerMap(current)) {
|
|
138
|
+
return { ok: false, line: `${harness}: ${path} mcpServers.fauxnix is not an object — not modified` };
|
|
139
|
+
}
|
|
140
|
+
if (sameMcpLaunchTuple(current, launch)) {
|
|
141
|
+
return { ok: true, line: `${harness}: already configured with an absolute launcher (${path})` };
|
|
142
|
+
}
|
|
143
|
+
if (current != null && !isLegacyFauxnixCommand(current)) {
|
|
144
|
+
return { ok: true, line: `${harness}: already configured (${path})` };
|
|
145
|
+
}
|
|
146
|
+
// New entry, or the pre-#252 `command: "fauxnix"` form that direct-spawn
|
|
147
|
+
// MCP clients cannot execute on Windows — both get the absolute launcher.
|
|
148
|
+
servers.fauxnix = {
|
|
149
|
+
...(isServerMap(current) ? current : {}),
|
|
150
|
+
command: launch.command,
|
|
151
|
+
args: [...launch.args],
|
|
136
152
|
};
|
|
137
|
-
return writeJson(path, data, harness, existed, 'added mcpServers.fauxnix');
|
|
153
|
+
return writeJson(path, data, harness, existed, current == null ? 'added mcpServers.fauxnix' : 'upgraded mcpServers.fauxnix to the spawn-safe absolute launcher (#252)');
|
|
138
154
|
}
|
|
139
|
-
function patchOpenCode(path) {
|
|
155
|
+
function patchOpenCode(path, launch) {
|
|
140
156
|
const read = readJsonObject(path);
|
|
141
157
|
if (read.state === 'invalid') {
|
|
142
158
|
return { ok: false, line: `opencode: ${path} is ${read.reason} — not modified` };
|
|
143
159
|
}
|
|
144
160
|
const existed = read.state !== 'missing';
|
|
145
161
|
const data = read.state === 'ok' ? read.data : {};
|
|
146
|
-
if (hasOpenCodeFauxnix(data)) {
|
|
147
|
-
return { ok: true, line: `opencode: already configured (${path})` };
|
|
148
|
-
}
|
|
149
162
|
if (data.mcp != null && !isServerMap(data.mcp)) {
|
|
150
163
|
return { ok: false, line: `opencode: ${path} mcp is not an object — not modified` };
|
|
151
164
|
}
|
|
152
165
|
if (!isServerMap(data.mcp))
|
|
153
166
|
data.mcp = {};
|
|
154
167
|
const mcp = data.mcp;
|
|
155
|
-
const payload = { type:
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
168
|
+
const payload = { type: 'local', command: [launch.command, ...launch.args] };
|
|
169
|
+
const slot = isServerMap(mcp.servers) ? mcp.servers : mcp;
|
|
170
|
+
const where = isServerMap(mcp.servers) ? 'mcp.servers.fauxnix' : 'mcp.fauxnix';
|
|
171
|
+
const current = slot.fauxnix;
|
|
172
|
+
if (current != null && !isLegacyFauxnixCommand(current)) {
|
|
173
|
+
return { ok: true, line: `opencode: already configured (${path})` };
|
|
159
174
|
}
|
|
160
|
-
|
|
161
|
-
|
|
175
|
+
const change = current == null ? `added ${where}` : `upgraded ${where} to the spawn-safe absolute launcher (#252)`;
|
|
176
|
+
slot.fauxnix = payload;
|
|
177
|
+
return writeJson(path, data, 'opencode', existed, change);
|
|
162
178
|
}
|
|
163
|
-
function patchCodex(path) {
|
|
179
|
+
function patchCodex(path, launch) {
|
|
164
180
|
const existed = existsSync(path);
|
|
165
181
|
if (!existed) {
|
|
166
|
-
const written = writeText(path, tomlTable('\n'));
|
|
182
|
+
const written = writeText(path, tomlTable('\n', launch));
|
|
167
183
|
if (!written.ok)
|
|
168
184
|
return { ok: false, line: `codex: failed to write ${path}: ${written.error}` };
|
|
169
185
|
return { ok: true, line: `codex: created ${path}` };
|
|
@@ -173,11 +189,18 @@ function patchCodex(path) {
|
|
|
173
189
|
return { ok: false, line: `codex: ${path} is unreadable — not modified` };
|
|
174
190
|
}
|
|
175
191
|
if (hasCodexFauxnix(stripBom(text))) {
|
|
176
|
-
|
|
192
|
+
const upgraded = upgradeCodexLegacyTable(text, launch);
|
|
193
|
+
if (upgraded === undefined) {
|
|
194
|
+
return { ok: true, line: `codex: already configured (${path})` };
|
|
195
|
+
}
|
|
196
|
+
const written = writeText(path, upgraded);
|
|
197
|
+
if (!written.ok)
|
|
198
|
+
return { ok: false, line: `codex: failed to write ${path}: ${written.error}` };
|
|
199
|
+
return { ok: true, line: `codex: patched ${path} (upgraded mcp_servers.fauxnix to the spawn-safe absolute launcher (#252))` };
|
|
177
200
|
}
|
|
178
201
|
const nl = text.includes('\r\n') ? '\r\n' : '\n';
|
|
179
202
|
if (stripBom(text).trim() === '') {
|
|
180
|
-
const written = writeText(path, tomlTable(nl));
|
|
203
|
+
const written = writeText(path, tomlTable(nl, launch));
|
|
181
204
|
if (!written.ok)
|
|
182
205
|
return { ok: false, line: `codex: failed to write ${path}: ${written.error}` };
|
|
183
206
|
return { ok: true, line: `codex: patched ${path} (appended [mcp_servers.fauxnix])` };
|
|
@@ -187,13 +210,33 @@ function patchCodex(path) {
|
|
|
187
210
|
body += nl;
|
|
188
211
|
if (!body.endsWith(nl + nl))
|
|
189
212
|
body += nl;
|
|
190
|
-
const written = writeText(path, body + tomlTable(nl));
|
|
213
|
+
const written = writeText(path, body + tomlTable(nl, launch));
|
|
191
214
|
if (!written.ok)
|
|
192
215
|
return { ok: false, line: `codex: failed to write ${path}: ${written.error}` };
|
|
193
216
|
return { ok: true, line: `codex: patched ${path} (appended [mcp_servers.fauxnix])` };
|
|
194
217
|
}
|
|
195
|
-
|
|
196
|
-
|
|
218
|
+
/**
|
|
219
|
+
* TOML literal strings (single quotes) keep Windows backslash paths intact
|
|
220
|
+
* without escape processing.
|
|
221
|
+
*/
|
|
222
|
+
function tomlTable(nl, launch) {
|
|
223
|
+
return (`[mcp_servers.fauxnix]${nl}` +
|
|
224
|
+
`command = '${launch.command.replace(/'/g, "''")}'${nl}` +
|
|
225
|
+
`args = ['${launch.args[0].replace(/'/g, "''")}', 'mcp']${nl}`);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Rewrite only the table our own installer wrote pre-#252 — the exact
|
|
229
|
+
* `command = "fauxnix"` + `args = ["mcp"]` spelling inside the fauxnix
|
|
230
|
+
* table. Anything else (user-edited, differently spelled) is left alone.
|
|
231
|
+
*/
|
|
232
|
+
function upgradeCodexLegacyTable(text, launch) {
|
|
233
|
+
const re = /(\[mcp_servers\.fauxnix\][^\[]*?)^[ \t]*command[ \t]*=[ \t]*"fauxnix"[ \t]*$[\s\S]*?^[ \t]*args[ \t]*=[ \t]*\["mcp"\][ \t]*$/m;
|
|
234
|
+
if (!re.test(text))
|
|
235
|
+
return undefined;
|
|
236
|
+
const nl = text.includes('\r\n') ? '\r\n' : '\n';
|
|
237
|
+
return text.replace(re, (_m, head) => head +
|
|
238
|
+
`command = '${launch.command.replace(/'/g, "''")}'${nl}` +
|
|
239
|
+
`args = ['${launch.args[0].replace(/'/g, "''")}', 'mcp']`);
|
|
197
240
|
}
|
|
198
241
|
function writeJson(path, data, harness, existed, change) {
|
|
199
242
|
const written = writeText(path, JSON.stringify(data, null, 2) + '\n');
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type McpLaunchTuple = {
|
|
2
|
+
command: string;
|
|
3
|
+
args: string[];
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Spawn-safe launch form for every harness config (#252): the absolute Node
|
|
7
|
+
* executable plus this installation's absolute built entry. A bare
|
|
8
|
+
* `fauxnix` command is an extension-less npm shim on Windows — MCP clients
|
|
9
|
+
* that spawn the server directly via CreateProcess cannot execute it. The
|
|
10
|
+
* absolute tuple is immune to PATH and shim-resolution differences on every
|
|
11
|
+
* platform.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveMcpLaunchTuple(): {
|
|
14
|
+
ok: true;
|
|
15
|
+
value: McpLaunchTuple;
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
reason: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function sameMcpLaunchTuple(value: unknown, expected: McpLaunchTuple): boolean;
|
|
21
|
+
/** The pre-#252 config form: `{ command: "fauxnix", args: ["mcp"] }`. */
|
|
22
|
+
export declare function isLegacyFauxnixCommand(value: unknown): boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
/**
|
|
5
|
+
* Spawn-safe launch form for every harness config (#252): the absolute Node
|
|
6
|
+
* executable plus this installation's absolute built entry. A bare
|
|
7
|
+
* `fauxnix` command is an extension-less npm shim on Windows — MCP clients
|
|
8
|
+
* that spawn the server directly via CreateProcess cannot execute it. The
|
|
9
|
+
* absolute tuple is immune to PATH and shim-resolution differences on every
|
|
10
|
+
* platform.
|
|
11
|
+
*/
|
|
12
|
+
export function resolveMcpLaunchTuple() {
|
|
13
|
+
const command = process.execPath;
|
|
14
|
+
const entry = fileURLToPath(new URL('../dist/index.js', import.meta.url));
|
|
15
|
+
if (!isAbsolute(command) || !existsSync(command)) {
|
|
16
|
+
return {
|
|
17
|
+
ok: false,
|
|
18
|
+
reason: 'cannot locate the Node.js executable; reinstall Node.js, then retry `fauxnix install`',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (!isAbsolute(entry) || !existsSync(entry)) {
|
|
22
|
+
return {
|
|
23
|
+
ok: false,
|
|
24
|
+
reason: `cannot locate the built fauxnix entry at ${entry}; run \`npm run build\` or reinstall fauxnix-cli, then retry \`fauxnix install\``,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return { ok: true, value: { command, args: [entry, 'mcp'] } };
|
|
28
|
+
}
|
|
29
|
+
export function sameMcpLaunchTuple(value, expected) {
|
|
30
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
31
|
+
return false;
|
|
32
|
+
const rec = value;
|
|
33
|
+
return (rec.command === expected.command &&
|
|
34
|
+
Array.isArray(rec.args) &&
|
|
35
|
+
rec.args.length === expected.args.length &&
|
|
36
|
+
rec.args.every((part, index) => part === expected.args[index]));
|
|
37
|
+
}
|
|
38
|
+
/** The pre-#252 config form: `{ command: "fauxnix", args: ["mcp"] }`. */
|
|
39
|
+
export function isLegacyFauxnixCommand(value) {
|
|
40
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
41
|
+
return false;
|
|
42
|
+
const rec = value;
|
|
43
|
+
return rec.command === 'fauxnix' || (Array.isArray(rec.command) && rec.command[0] === 'fauxnix');
|
|
44
|
+
}
|
package/dist/mcp.js
CHANGED
|
@@ -251,8 +251,16 @@ export async function startMcpServer() {
|
|
|
251
251
|
const onShutdown = () => {
|
|
252
252
|
void shutdown().catch(() => undefined);
|
|
253
253
|
};
|
|
254
|
+
// Register before the cold-start prewarm: a signal during prewarm must
|
|
255
|
+
// still dispose the host and its private state directory (#256).
|
|
256
|
+
process.on('SIGINT', onShutdown);
|
|
257
|
+
process.on('SIGTERM', onShutdown);
|
|
254
258
|
try {
|
|
255
259
|
await session.prewarm();
|
|
260
|
+
if (shutdownPromise) {
|
|
261
|
+
await shutdownPromise;
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
256
264
|
server.tool(TOOL_NAME, TOOL_DESCRIPTION, {
|
|
257
265
|
command: z.string().describe('The bash-style command line to run'),
|
|
258
266
|
timeout_ms: z
|
|
@@ -377,8 +385,6 @@ export async function startMcpServer() {
|
|
|
377
385
|
const transport = new StdioServerTransport();
|
|
378
386
|
input.on('end', onShutdown);
|
|
379
387
|
input.on('close', onShutdown);
|
|
380
|
-
process.on('SIGINT', onShutdown);
|
|
381
|
-
process.on('SIGTERM', onShutdown);
|
|
382
388
|
transport.onclose = onShutdown;
|
|
383
389
|
await server.connect(transport);
|
|
384
390
|
}
|
package/dist/parser.js
CHANGED
|
@@ -93,8 +93,20 @@ export function tokenize(input) {
|
|
|
93
93
|
}
|
|
94
94
|
// the fd digits were consumed earlier; advance past the operator tail only
|
|
95
95
|
advance = matched.length - fdDigits.length;
|
|
96
|
+
// fd 1 is stdout: `1>f` / `1>>f` are the same redirects as `>f` / `>>f`
|
|
97
|
+
if (matched === '1>')
|
|
98
|
+
matched = '>';
|
|
99
|
+
else if (matched === '1>>')
|
|
100
|
+
matched = '>>';
|
|
96
101
|
fdDigits = '';
|
|
97
102
|
}
|
|
103
|
+
else if (matched === '>' &&
|
|
104
|
+
input.startsWith('&2', i + 1) &&
|
|
105
|
+
!/[^\s;|&<>()]/.test(input[i + 3] ?? ' ')) {
|
|
106
|
+
// `>&2` is shorthand for `1>&2`
|
|
107
|
+
matched = '1>&2';
|
|
108
|
+
advance = 3;
|
|
109
|
+
}
|
|
98
110
|
if (matched === '<<') {
|
|
99
111
|
throw new FauxnixParseError('fauxnix: heredocs (<<) are not supported yet. Pass the text via echo pipe or a temp file instead.');
|
|
100
112
|
}
|
|
@@ -1264,6 +1276,9 @@ export function parseCommand(input) {
|
|
|
1264
1276
|
next();
|
|
1265
1277
|
continue;
|
|
1266
1278
|
}
|
|
1279
|
+
if (t.type === 'OP' && /^\d+[<>]/.test(t.op) && !isRedirectOp(t.op)) {
|
|
1280
|
+
normalizeRedirect(t.op);
|
|
1281
|
+
}
|
|
1267
1282
|
if (t.type === 'OP' && isRedirectOp(t.op)) {
|
|
1268
1283
|
const op = t.op;
|
|
1269
1284
|
next();
|
package/dist/ps-host.d.ts
CHANGED
|
@@ -103,6 +103,11 @@ export declare class PowerShellHost {
|
|
|
103
103
|
ready(): Promise<HostInvokeResult | null>;
|
|
104
104
|
invoke(script: string, env: HostRequestEnv, timeoutMs: number, signal?: AbortSignal, limits?: HostOutputLimits): Promise<HostInvokeResult>;
|
|
105
105
|
drainNativeStderr(): Buffer;
|
|
106
|
+
/**
|
|
107
|
+
* Synchronous best-effort termination for process-exit paths, where the
|
|
108
|
+
* async stop() cannot be awaited. Fails pending waiters like stop().
|
|
109
|
+
*/
|
|
110
|
+
killSync(): void;
|
|
106
111
|
stop(): Promise<void>;
|
|
107
112
|
private cancelledResult;
|
|
108
113
|
private invokeSerial;
|
package/dist/ps-host.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
1
2
|
import { spawn } from 'node:child_process';
|
|
2
3
|
import { closeSync, openSync, readSync, rmSync, statSync, writeFileSync, writeSync, } from 'node:fs';
|
|
3
4
|
import { hostBootstrapScript } from './translator.js';
|
|
@@ -109,6 +110,31 @@ export class PowerShellHost {
|
|
|
109
110
|
this.stderrChunks = [];
|
|
110
111
|
return b;
|
|
111
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Synchronous best-effort termination for process-exit paths, where the
|
|
115
|
+
* async stop() cannot be awaited. Fails pending waiters like stop().
|
|
116
|
+
*/
|
|
117
|
+
killSync() {
|
|
118
|
+
this.cancelNativeCapture();
|
|
119
|
+
const proc = this.proc;
|
|
120
|
+
this.proc = null;
|
|
121
|
+
this.closed = true;
|
|
122
|
+
this.failWaiters(new Error('fauxnix: PowerShell host stopped'));
|
|
123
|
+
if (!proc)
|
|
124
|
+
return;
|
|
125
|
+
try {
|
|
126
|
+
proc.stdin?.destroy();
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
/* ignore */
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
proc.kill();
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
/* ignore */
|
|
136
|
+
}
|
|
137
|
+
}
|
|
112
138
|
async stop() {
|
|
113
139
|
this.cancelNativeCapture();
|
|
114
140
|
const proc = this.proc;
|
|
@@ -186,7 +212,7 @@ export class PowerShellHost {
|
|
|
186
212
|
}
|
|
187
213
|
if (started)
|
|
188
214
|
return { ...started, cancelled: false, truncated: false };
|
|
189
|
-
const id = 'f' + Date.now().toString(36) +
|
|
215
|
+
const id = 'f' + Date.now().toString(36) + randomBytes(6).toString('hex');
|
|
190
216
|
const resolvedLimits = { ...limits };
|
|
191
217
|
if (resolvedLimits.stdoutMode === 'spool') {
|
|
192
218
|
resolvedLimits.stdoutSpoolPath = this.hostFile + '.' + id + '.stdout';
|
|
@@ -377,6 +403,17 @@ export class PowerShellHost {
|
|
|
377
403
|
windowsHide: true,
|
|
378
404
|
});
|
|
379
405
|
this.proc = child;
|
|
406
|
+
child.stdin.on('error', (e) => {
|
|
407
|
+
// A closed host input pipe reports EPIPE asynchronously; write()'s
|
|
408
|
+
// try/catch cannot contain it. Fail this request through the normal
|
|
409
|
+
// dead-host path and leave the next invocation free to start again.
|
|
410
|
+
if (this.proc !== child)
|
|
411
|
+
return;
|
|
412
|
+
this.closeErr = e;
|
|
413
|
+
this.closed = true;
|
|
414
|
+
this.failWaiters(e);
|
|
415
|
+
this.cancelNativeCapture();
|
|
416
|
+
});
|
|
380
417
|
child.stdout.on('data', (d) => {
|
|
381
418
|
if (this.proc !== child)
|
|
382
419
|
return;
|
|
@@ -393,6 +430,7 @@ export class PowerShellHost {
|
|
|
393
430
|
this.closeErr = e;
|
|
394
431
|
this.closed = true;
|
|
395
432
|
this.failWaiters(e);
|
|
433
|
+
this.cancelNativeCapture();
|
|
396
434
|
});
|
|
397
435
|
child.on('close', (c) => {
|
|
398
436
|
if (this.proc !== child)
|
|
@@ -401,6 +439,7 @@ export class PowerShellHost {
|
|
|
401
439
|
this.closed = true;
|
|
402
440
|
this.proc = null;
|
|
403
441
|
this.failWaiters(new Error('fauxnix: powershell host closed'));
|
|
442
|
+
this.cancelNativeCapture();
|
|
404
443
|
});
|
|
405
444
|
try {
|
|
406
445
|
const readyLine = await this.nextReadyLine(READY_TIMEOUT_MS);
|
|
@@ -512,7 +551,7 @@ export class PowerShellHost {
|
|
|
512
551
|
let outSeq = 0;
|
|
513
552
|
let errSeq = 0;
|
|
514
553
|
let end = null;
|
|
515
|
-
const nativePromise = this.beginNativeCapture(id, limits?.stderrMode ?? 'capture', limits?.stderrLimit ?? DEFAULT_STDERR_LIMIT, limits?.nativeStderrSpoolPath, timeoutMs
|
|
554
|
+
const nativePromise = this.beginNativeCapture(id, limits?.stderrMode ?? 'capture', limits?.stderrLimit ?? DEFAULT_STDERR_LIMIT, limits?.nativeStderrSpoolPath, timeoutMs);
|
|
516
555
|
// collectV2 can leave through a frame timeout before it reaches the await
|
|
517
556
|
// below. Attach a handler immediately so teardown never reports a stray
|
|
518
557
|
// promise rejection; the awaited path still receives the same failure.
|
|
@@ -547,26 +586,11 @@ export class PowerShellHost {
|
|
|
547
586
|
end = f;
|
|
548
587
|
}
|
|
549
588
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
new Promise((_, reject) => {
|
|
556
|
-
markerTimer = setTimeout(() => reject(new Error('fauxnix: native stderr marker missing')), 2000);
|
|
557
|
-
}),
|
|
558
|
-
]);
|
|
559
|
-
nativeBytes = captured.bytesSeen;
|
|
560
|
-
}
|
|
561
|
-
catch (e) {
|
|
562
|
-
this.cancelNativeCapture();
|
|
563
|
-
if (e instanceof NativeStderrSpoolError)
|
|
564
|
-
throw e;
|
|
565
|
-
}
|
|
566
|
-
finally {
|
|
567
|
-
if (markerTimer)
|
|
568
|
-
clearTimeout(markerTimer);
|
|
569
|
-
}
|
|
589
|
+
// The end frame and native marker arrive on independent pipes. Finishing
|
|
590
|
+
// stdout does not complete the request: cancellation, pipe failure and
|
|
591
|
+
// the original deadline still apply while native stderr is pending.
|
|
592
|
+
// Let invokeSerial handle failures so it also removes partial spools.
|
|
593
|
+
const { bytesSeen: nativeBytes } = await nativePromise;
|
|
570
594
|
const capturedErr = Buffer.from(Buffer.concat(err));
|
|
571
595
|
let native = Buffer.alloc(0);
|
|
572
596
|
let nativeTruncated = false;
|
|
@@ -601,7 +625,7 @@ export class PowerShellHost {
|
|
|
601
625
|
if (this.nativeCapture?.id !== id)
|
|
602
626
|
return;
|
|
603
627
|
const state = this.nativeCapture;
|
|
604
|
-
const failure = state.ioError ?? new Error('fauxnix: native stderr marker
|
|
628
|
+
const failure = state.ioError ?? Object.assign(new Error('fauxnix: native stderr marker timed out'), { timedOut: true });
|
|
605
629
|
this.closeNativeSpool(state);
|
|
606
630
|
this.nativeCapture = null;
|
|
607
631
|
reject(failure);
|
package/dist/qwen-launch.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare
|
|
6
|
-
ok: true;
|
|
7
|
-
value: QwenLaunchTuple;
|
|
8
|
-
} | {
|
|
9
|
-
ok: false;
|
|
10
|
-
reason: string;
|
|
11
|
-
};
|
|
12
|
-
export declare function sameQwenLaunchTuple(value: unknown, expected: QwenLaunchTuple): boolean;
|
|
1
|
+
import type { McpLaunchTuple } from './mcp-launch.js';
|
|
2
|
+
import { resolveMcpLaunchTuple, sameMcpLaunchTuple } from './mcp-launch.js';
|
|
3
|
+
export type QwenLaunchTuple = McpLaunchTuple;
|
|
4
|
+
export declare const resolveQwenLaunchTuple: typeof resolveMcpLaunchTuple;
|
|
5
|
+
export declare const sameQwenLaunchTuple: typeof sameMcpLaunchTuple;
|
package/dist/qwen-launch.js
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
const entry = fileURLToPath(new URL('../dist/index.js', import.meta.url));
|
|
7
|
-
if (!isAbsolute(command) || !existsSync(command)) {
|
|
8
|
-
return {
|
|
9
|
-
ok: false,
|
|
10
|
-
reason: 'cannot locate the Node.js executable; reinstall Node.js, then retry `fauxnix install --qwen`',
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
if (!isAbsolute(entry) || !existsSync(entry)) {
|
|
14
|
-
return {
|
|
15
|
-
ok: false,
|
|
16
|
-
reason: `cannot locate the built fauxnix entry at ${entry}; run \`npm run build\` or reinstall fauxnix-cli, then retry \`fauxnix install --qwen\``,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return { ok: true, value: { command, args: [entry, 'mcp'] } };
|
|
20
|
-
}
|
|
21
|
-
export function sameQwenLaunchTuple(value, expected) {
|
|
22
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
23
|
-
return false;
|
|
24
|
-
const rec = value;
|
|
25
|
-
return (rec.command === expected.command &&
|
|
26
|
-
Array.isArray(rec.args) &&
|
|
27
|
-
rec.args.length === expected.args.length &&
|
|
28
|
-
rec.args.every((part, index) => part === expected.args[index]));
|
|
29
|
-
}
|
|
1
|
+
import { resolveMcpLaunchTuple, sameMcpLaunchTuple } from './mcp-launch.js';
|
|
2
|
+
// The Qwen launcher pioneered the absolute spawn-safe tuple; every harness
|
|
3
|
+
// now uses it (#252). These aliases keep the historical import surface.
|
|
4
|
+
export const resolveQwenLaunchTuple = resolveMcpLaunchTuple;
|
|
5
|
+
export const sameQwenLaunchTuple = sameMcpLaunchTuple;
|
package/dist/translator.d.ts
CHANGED
|
@@ -67,6 +67,15 @@ export declare function literalOfWord(w: Word): string | null;
|
|
|
67
67
|
* Literal paths get POSIX-ish normalization (/dev/null, /tmp, /d/...).
|
|
68
68
|
*/
|
|
69
69
|
export declare function operandExpr(w: Word): string;
|
|
70
|
+
/**
|
|
71
|
+
* Operand expression for handlers whose runtime glob step is `fx-glob`
|
|
72
|
+
* (#255 quote-aware globbing): bash globs a word only where glob characters
|
|
73
|
+
* sat UNQUOTED — quoted parts and backslash-escaped characters are literal
|
|
74
|
+
* even when a variable expands to something containing metas, while unquoted
|
|
75
|
+
* expansions stay glob-active. `fx-glob` unescapes the pattern when no file
|
|
76
|
+
* matches, so unmatched literals keep their shell spelling.
|
|
77
|
+
*/
|
|
78
|
+
export declare function globOperandExpr(w: Word): string;
|
|
70
79
|
/**
|
|
71
80
|
* `${name[@]}` / `"pre${name[@]}post"` — one argv per element.
|
|
72
81
|
* Unquoted `${name[*]}` also splats (bash); quoted `"${name[*]}"` stays one join.
|