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.

v0.5.3 — add mercury upgrade command, ENOTEMPTY fix

Salman Qureshi5a74c54c994b
diff --git a/package-lock.json b/package-lock.json
index 9d475989..828ef007 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@cosmicstack/mercury-agent",
- "version": "0.5.2",
+ "version": "0.5.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@cosmicstack/mercury-agent",
- "version": "0.5.2",
+ "version": "0.5.3",
"license": "MIT",
"dependencies": {
"@ai-sdk/anthropic": "^1.2.0",
diff --git a/package.json b/package.json
index 0619aeaa..1fcea891 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@cosmicstack/mercury-agent",
- "version": "0.5.2",
+ "version": "0.5.3",
"description": "Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI or Telegram.",
"type": "module",
"main": "dist/index.js",
diff --git a/src/index.ts b/src/index.ts
index 4a22945a..91bca0fa 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1335,4 +1335,69 @@ serviceCmd
showServiceStatus();
});
+program
+ .command('upgrade')
+ .description('Upgrade Mercury to the latest version from npm')
+ .action(async () => {
+ console.log('');
+ console.log(chalk.cyan(` Mercury ${chalk.white(`v${pkgVersion}`)}`));
+ console.log('');
+
+ const daemon = getDaemonStatus();
+ if (daemon.running) {
+ console.log(chalk.dim(' Stopping background daemon...'));
+ stopDaemon();
+ await new Promise((r) => setTimeout(r, 1000));
+ console.log(chalk.green(' ✓ Daemon stopped'));
+ }
+
+ console.log(chalk.dim(' Checking for latest version...'));
+ const { execSync } = await import('node:child_process');
+
+ let latestVersion = '';
+ try {
+ latestVersion = execSync('npm view @cosmicstack/mercury-agent version', { encoding: 'utf-8' }).trim();
+ } catch {
+ console.log(chalk.red(' ✗ Failed to fetch latest version from npm'));
+ console.log('');
+ return;
+ }
+
+ console.log(chalk.dim(` Latest: v${latestVersion}`));
+
+ if (latestVersion === pkgVersion) {
+ console.log(chalk.green(` ✓ Already on the latest version (v${pkgVersion})`));
+ console.log('');
+ return;
+ }
+
+ console.log(chalk.dim(` Upgrading v${pkgVersion} → v${latestVersion}...`));
+ console.log('');
+
+ try {
+ execSync('npm rm -g @cosmicstack/mercury-agent', { stdio: 'pipe' });
+ } catch {
+ // ignore — old package may not exist or ENOTEMPTY
+ try {
+ const globalDir = execSync('npm root -g', { encoding: 'utf-8' }).trim();
+ const pkgDir = join(globalDir, '@cosmicstack', 'mercury-agent');
+ const { rmSync } = await import('node:fs');
+ try { rmSync(pkgDir, { recursive: true, force: true }); } catch {}
+ } catch {}
+ }
+
+ try {
+ execSync('npm i -g @cosmicstack/mercury-agent@latest', { stdio: 'inherit' });
+ console.log('');
+ console.log(chalk.green(` ✓ Upgraded to v${latestVersion}`));
+ console.log(chalk.dim(' Run `mercury` to start the new version.'));
+ } catch {
+ console.log('');
+ console.log(chalk.red(' ✗ Upgrade failed. Try manually:'));
+ console.log(chalk.dim(' npm rm -g @cosmicstack/mercury-agent && npm i -g @cosmicstack/mercury-agent'));
+ }
+
+ console.log('');
+ });
+
program.parse();