Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

fix(plugins): tar calls work with GNU tar on Windows

Salman Qureshi117741c9f56b
diff --git a/plugins/whatsapp/package.mjs b/plugins/whatsapp/package.mjs
index 46b09b70..5c918d6b 100644
--- a/plugins/whatsapp/package.mjs
+++ b/plugins/whatsapp/package.mjs
@@ -7,7 +7,7 @@ import { createHash } from 'node:crypto';
import { execFileSync } from 'node:child_process';
import { chmodSync, copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
-import { dirname, join, resolve } from 'node:path';
+import { basename, dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const [binary, platform, outDir] = process.argv.slice(2);
@@ -32,7 +32,8 @@ writeFileSync(join(stage, 'mercury-plugin.json'), `${JSON.stringify(manifest, nu
mkdirSync(outDir, { recursive: true });
const out = resolve(outDir, `mercury-plugin-${platform}.tgz`);
-execFileSync('tar', ['-czf', out, '-C', stage, 'mercury-plugin.json', 'bin', 'README.md']);
+// Archive name relative to cwd: GNU tar on Windows reads "D:\\…" as a remote host.
+execFileSync('tar', ['-czf', basename(out), '-C', stage, 'mercury-plugin.json', 'bin', 'README.md'], { cwd: dirname(out) });
const sha = createHash('sha256').update(readFileSync(out)).digest('hex');
writeFileSync(`${out}.sha256`, `${sha} mercury-plugin-${platform}.tgz\n`);
rmSync(stage, { recursive: true, force: true });
diff --git a/src/plugins/installer.ts b/src/plugins/installer.ts
index d74cdbbb..fddf3a8b 100644
--- a/src/plugins/installer.ts
+++ b/src/plugins/installer.ts
@@ -11,7 +11,7 @@ import { createHash, randomBytes } from 'node:crypto';
import { execFile } from 'node:child_process';
import { chmodSync, cpSync, createReadStream, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
import { homedir } from 'node:os';
-import { join, relative, resolve, sep } from 'node:path';
+import { basename, dirname, join, relative, resolve, sep } from 'node:path';
import { promisify } from 'node:util';
import { guardedFetch } from '../utils/ssrf.js';
import { logger } from '../utils/logger.js';
@@ -146,7 +146,9 @@ async function extractTgz(archive: string, into: string): Promise<void> {
// System tar (bsdtar on macOS/Windows, GNU tar on Linux): both refuse
// absolute paths and ".." members by default. We re-check every entry below.
try {
- await execFileAsync('tar', ['-xzf', archive, '-C', into], { timeout: 120_000, windowsHide: true, maxBuffer: 1024 * 1024 });
+ // Run from the archive's folder and pass only its name: GNU tar (e.g. Git
+ // for Windows' tar on PATH) reads "C:\\…" as a remote host "C".
+ await execFileAsync('tar', ['-xzf', basename(archive), '-C', into], { cwd: dirname(archive), timeout: 120_000, windowsHide: true, maxBuffer: 1024 * 1024 });
} catch (err) {
throw new Error(`Couldn't unpack the plugin archive: ${(err as Error).message.split('\n')[0]}`);
}
diff --git a/src/plugins/scaffold.ts b/src/plugins/scaffold.ts
index e3556a5e..66b9b5be 100644
--- a/src/plugins/scaffold.ts
+++ b/src/plugins/scaffold.ts
@@ -6,7 +6,7 @@
*/
import { execFile } from 'node:child_process';
import { existsSync, mkdirSync, readdirSync, statSync, writeFileSync } from 'node:fs';
-import { basename, join, resolve } from 'node:path';
+import { basename, dirname, join, resolve } from 'node:path';
import { promisify } from 'node:util';
import semver from 'semver';
import { checkTree, loadManifest, sha256File } from './installer.js';
@@ -211,7 +211,8 @@ export async function packPlugin(dir: string, outDir = process.cwd()): Promise<P
const file = join(resolve(outDir), `${manifest.id}-${manifest.version}.tgz`);
const skip = new Set(['.git', 'node_modules', '.DS_Store']);
const members = readdirSync(root).filter((n) => !skip.has(n) && !n.endsWith('.tgz') && !n.endsWith('.d.ts'));
- await execFileAsync('tar', ['-czf', file, '-C', root, ...members]);
+ // Archive name relative to cwd: GNU tar reads "C:\\…" as a remote host.
+ await execFileAsync('tar', ['-czf', basename(file), '-C', root, ...members], { cwd: dirname(file), windowsHide: true });
const sha256 = await sha256File(file);
const size = statSync(file).size;
return {