Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(upgrade): no-op when already on the channel's latest; --force to reinstall (1.3.6)
Salman Qureshi07b3ca834637
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6a6f4829..24b01f1b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,9 @@# Changelog+## 1.3.6 — hotfix: `mercury upgrade` is a no-op when already current++- **`mercury upgrade` / `mercury-dev upgrade` re-installed (and restarted the daemon) even on the latest build.** They now resolve the channel's newest version first — stable from `/releases/latest`, dev from the rolling `mercury-dev-latest` release — and stop with "Already on the latest version" without touching the daemon or the binary. `--force` reinstalls anyway.+## 1.3.5 — hotfix: the Windows installer on Windows PowerShell 5.1- **`irm mercuryagent.sh/install.ps1 | iex` failed with "checksums.txt must contain exactly one checksum for mercury-win-x64.exe"** on stock Windows PowerShell 5.1 — and the window closed before you could read it. GitHub serves `checksums.txt` as `application/octet-stream`, for which PowerShell 5.1 returns a `byte[]` from `Invoke-WebRequest`; the installer now decodes it (PowerShell 7 was unaffected). A failure now waits for Enter before closing the window (`MERCURY_NO_PAUSE=1` for automation).diff --git a/README.md b/README.mdindex 2d9640ff..d08efcee 100644--- a/README.md+++ b/README.md@@ -21,7 +21,7 @@</p><p align="center">- <strong>🔖 Current Stable: v1.3.5 — Steady Mercury</strong>+ <strong>🔖 Current Stable: v1.3.6 — Steady Mercury</strong></p><p align="center">diff --git a/package-lock.json b/package-lock.jsonindex 1e226a1e..f092bf20 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "@cosmicstack/mercury-agent",- "version": "1.3.4",+ "version": "1.3.6","lockfileVersion": 2,"requires": true,"packages": {"": {"name": "@cosmicstack/mercury-agent",- "version": "1.3.4",+ "version": "1.3.6","hasInstallScript": true,"license": "MIT","dependencies": {diff --git a/package.json b/package.jsonindex a88fcc37..7fdfd44a 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "@cosmicstack/mercury-agent",- "version": "1.3.5",+ "version": "1.3.6","description": "Soul-driven AI agent with Second Brain memory, 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/cli/latest-version.test.ts b/src/cli/latest-version.test.tsnew file mode 100644index 00000000..2d14da70--- /dev/null+++ b/src/cli/latest-version.test.ts@@ -0,0 +1,30 @@+import { describe, expect, it } from 'vitest';+import { readFileSync } from 'node:fs';+import { fileURLToPath } from 'node:url';+import { dirname, join } from 'node:path';+import { parseDevVersionFromReleaseName, parseVersionFromReleaseLocation } from './latest-version.js';++describe('latest version resolution (mercury upgrade is a no-op when current)', () => {+ it('reads the stable version from the /releases/latest redirect', () => {+ expect(parseVersionFromReleaseLocation('https://github.com/cosmicstack-labs/mercury-agent/releases/tag/v1.3.5')).toBe('1.3.5');+ expect(parseVersionFromReleaseLocation('https://github.com/x/y/releases/tag/1.4.0/')).toBe('1.4.0');+ expect(parseVersionFromReleaseLocation('https://github.com/x/y/releases')).toBeNull();+ expect(parseVersionFromReleaseLocation(null)).toBeNull();+ });++ it('reads the dev version from the rolling release title', () => {+ expect(parseDevVersionFromReleaseName('Mercury Dev — 1.3.1-dev.20261011.d40a112')).toBe('1.3.1-dev.20261011.d40a112');+ expect(parseDevVersionFromReleaseName('Mercury Dev')).toBeNull();+ });++ it('the launcher checks the channel version before stopping the daemon or running an installer', () => {+ const index = readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'index.ts'), 'utf8').replace(/\r\n/g, '\n');+ const cmd = index.slice(index.indexOf(".command('upgrade')"), index.indexOf(".command('upgrade')") + 6000);+ const check = cmd.indexOf('fetchLatestVersion(');+ const stop = cmd.indexOf('await stopDaemon()');+ expect(check).toBeGreaterThan(0);+ expect(stop).toBeGreaterThan(check);+ expect(cmd).toContain("Already on the latest");+ expect(cmd).toContain("'--force'");+ });+});diff --git a/src/cli/latest-version.ts b/src/cli/latest-version.tsnew file mode 100644index 00000000..2246c3ac--- /dev/null+++ b/src/cli/latest-version.ts@@ -0,0 +1,40 @@+/**+ * What is the newest build on a channel? Asked by `mercury upgrade` BEFORE+ * it stops the daemon and re-runs an installer: an upgrade that is already+ * installed must be a no-op, not a restart.+ */+const REPO = 'cosmicstack-labs/mercury-agent';++/** `/releases/latest` redirects to `/releases/tag/vX.Y.Z` — the version is in the Location. */+export function parseVersionFromReleaseLocation(location: string | null | undefined): string | null {+ const m = String(location ?? '').match(/\/releases\/tag\/v?(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)\/?$/);+ return m ? m[1] : null;+}++/** The rolling dev release is titled "Mercury Dev — <version>"; the version is the truth. */+export function parseDevVersionFromReleaseName(name: string | null | undefined): string | null {+ const m = String(name ?? '').match(/(\d+\.\d+\.\d+-dev\.\d{8}\.[0-9a-f]+)/);+ return m ? m[1] : null;+}++export async function fetchLatestVersion(channel: 'stable' | 'dev', timeoutMs = 8000): Promise<string | null> {+ const controller = new AbortController();+ const timer = setTimeout(() => controller.abort(), timeoutMs);+ try {+ if (channel === 'dev') {+ const res = await fetch(`https://api.github.com/repos/${REPO}/releases/tags/mercury-dev-latest`, {+ signal: controller.signal,+ headers: { Accept: 'application/vnd.github+json', 'User-Agent': 'mercury-agent-upgrade' },+ });+ if (!res.ok) return null;+ const body = await res.json() as { name?: string };+ return parseDevVersionFromReleaseName(body.name);+ }+ const res = await fetch(`https://github.com/${REPO}/releases/latest`, { signal: controller.signal, redirect: 'manual' });+ return parseVersionFromReleaseLocation(res.headers.get('location'));+ } catch {+ return null;+ } finally {+ clearTimeout(timer);+ }+}diff --git a/src/index.ts b/src/index.tsindex f73d9ae5..f674b0cb 100644--- a/src/index.ts+++ b/src/index.ts@@ -4832,9 +4832,25 @@ serviceCmdprogram.command('upgrade').description('Upgrade Mercury to the latest version')- .action(async () => {+ .option('--force', 'Reinstall even when already on the latest version')+ .action(async (opts: { force?: boolean }) => {console.log('');console.log(chalk.cyan(` Mercury ${chalk.white(`v${pkgVersion}`)}`));+ // Already current? Say so and touch nothing — not the daemon, not the+ // binary. (This used to stop the daemon and re-run the installer+ // unconditionally: "upgrade" on the latest build was a restart.)+ if (!opts.force) {+ const { fetchLatestVersion } = await import('./cli/latest-version.js');+ const channel = isDevBuild(pkgVersion) ? 'dev' : 'stable';+ const latest = await fetchLatestVersion(channel);+ if (latest && latest === pkgVersion) {+ console.log(chalk.green(` ✓ Already on the latest ${channel === 'dev' ? 'dev build' : 'version'} (v${pkgVersion}). Nothing to do.`));+ console.log(chalk.dim(' Use mercury upgrade --force to reinstall anyway.'));+ console.log('');+ return;+ }+ if (latest) console.log(chalk.dim(` Latest on the ${channel} channel: v${latest}`));+ }// A dev binary upgrades itself in place on the same channel (re-running// the dev installer below); npm builds take the npm stable track.if (isDevBuild(pkgVersion)) {