ace-tool-rs 0.1.7 → 0.1.8
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/package.json +1 -1
- package/run.js +15 -7
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -7,6 +7,12 @@ const https = require("https");
|
|
|
7
7
|
const os = require("os");
|
|
8
8
|
const crypto = require("crypto");
|
|
9
9
|
|
|
10
|
+
// Note: We do not use 'kexec' to replace the process because the available packages
|
|
11
|
+
// are largely unmaintained or have compatibility issues with modern Node.js versions.
|
|
12
|
+
// Instead, we spawn the child and forward signals/stdio.
|
|
13
|
+
// Crucially, we ensure the wrapper ONLY writes to stderr (logs, extraction output)
|
|
14
|
+
// so that the Rust binary's stdout (MCP JSON-RPC) is the only thing on stdout.
|
|
15
|
+
|
|
10
16
|
const PACKAGE_NAME = "ace-tool-rs";
|
|
11
17
|
const REPO_OWNER = "missdeer";
|
|
12
18
|
const REPO_NAME = "ace-tool-rs";
|
|
@@ -203,7 +209,7 @@ async function getReleaseByTag(version) {
|
|
|
203
209
|
} catch (error) {
|
|
204
210
|
// If the specific version tag doesn't exist, fall back to latest
|
|
205
211
|
if (error.message.includes("404")) {
|
|
206
|
-
console.
|
|
212
|
+
console.error(
|
|
207
213
|
`Release v${version} not found, falling back to latest release...`
|
|
208
214
|
);
|
|
209
215
|
return getLatestRelease();
|
|
@@ -308,8 +314,9 @@ function downloadToFile(url, destPath, options = {}, redirectCount = 0) {
|
|
|
308
314
|
|
|
309
315
|
async function extractTarGz(archivePath, destDir) {
|
|
310
316
|
return new Promise((resolve, reject) => {
|
|
317
|
+
// Redirect stdout to stderr to prevent MCP corruption
|
|
311
318
|
const tar = spawn("tar", ["-xzf", archivePath, "-C", destDir], {
|
|
312
|
-
stdio: "
|
|
319
|
+
stdio: ["ignore", process.stderr, process.stderr],
|
|
313
320
|
});
|
|
314
321
|
tar.on("close", (code) => {
|
|
315
322
|
if (code === 0) resolve();
|
|
@@ -329,6 +336,7 @@ async function extractZip(archivePath, destDir) {
|
|
|
329
336
|
return new Promise((resolve, reject) => {
|
|
330
337
|
// Escape paths for PowerShell: escape backticks and single quotes
|
|
331
338
|
const escapePath = (p) => p.replace(/`/g, "``").replace(/'/g, "''");
|
|
339
|
+
// Redirect stdout to stderr to prevent MCP corruption
|
|
332
340
|
const unzipProcess = spawn(
|
|
333
341
|
"powershell",
|
|
334
342
|
[
|
|
@@ -338,7 +346,7 @@ async function extractZip(archivePath, destDir) {
|
|
|
338
346
|
"-Command",
|
|
339
347
|
`Expand-Archive -LiteralPath '${escapePath(archivePath)}' -DestinationPath '${escapePath(destDir)}' -Force`,
|
|
340
348
|
],
|
|
341
|
-
{ stdio: "
|
|
349
|
+
{ stdio: ["ignore", process.stderr, process.stderr] }
|
|
342
350
|
);
|
|
343
351
|
unzipProcess.on("close", (code) => {
|
|
344
352
|
if (code === 0) resolve();
|
|
@@ -416,7 +424,7 @@ async function downloadAndExtract(cacheDir) {
|
|
|
416
424
|
// Try to acquire lock
|
|
417
425
|
if (!acquireLock(lockPath)) {
|
|
418
426
|
// Wait for other process to complete
|
|
419
|
-
console.
|
|
427
|
+
console.error("Another process is downloading, waiting...");
|
|
420
428
|
let attempts = 0;
|
|
421
429
|
while (!fs.existsSync(binaryPath) && attempts < 60) {
|
|
422
430
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
@@ -436,7 +444,7 @@ async function downloadAndExtract(cacheDir) {
|
|
|
436
444
|
|
|
437
445
|
// Get release for the specific version (with retry)
|
|
438
446
|
const version = getPackageVersion();
|
|
439
|
-
console.
|
|
447
|
+
console.error(`Downloading ${PACKAGE_NAME} v${version}...`);
|
|
440
448
|
|
|
441
449
|
const release = await withRetry(() => getReleaseByTag(version));
|
|
442
450
|
const asset = release.assets.find((a) => a.name === assetName);
|
|
@@ -467,7 +475,7 @@ async function downloadAndExtract(cacheDir) {
|
|
|
467
475
|
);
|
|
468
476
|
|
|
469
477
|
// Extract to temporary directory
|
|
470
|
-
console.
|
|
478
|
+
console.error("Extracting...");
|
|
471
479
|
fs.mkdirSync(tempExtractDir, { recursive: true });
|
|
472
480
|
|
|
473
481
|
if (assetName.endsWith(".zip")) {
|
|
@@ -496,7 +504,7 @@ async function downloadAndExtract(cacheDir) {
|
|
|
496
504
|
fs.unlinkSync(tempArchive);
|
|
497
505
|
fs.rmSync(tempExtractDir, { recursive: true, force: true });
|
|
498
506
|
|
|
499
|
-
console.
|
|
507
|
+
console.error(`Installed ${PACKAGE_NAME} to ${binaryPath}`);
|
|
500
508
|
return binaryPath;
|
|
501
509
|
} catch (error) {
|
|
502
510
|
console.error(`Failed to download ${PACKAGE_NAME}: ${error.message}`);
|