Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
release: v1.1.12 — daemon hotfix for standalone binaries
Salman Qureshi587fad1bf944
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 51462da7..f51d8b16 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,23 @@# Changelog+## 1.1.12 — Daemon fix for standalone binaries++Hotfix on top of 1.1.11. The standalone single-file binaries shipped in 1.1.11 could not start in the background — which also meant Telegram never came online when Mercury was installed via the one-line installer (the recommended path for servers).++### Fixed++- **Daemon now starts correctly from standalone binaries** — `src/cli/daemon.ts` used to spawn the daemon as `[process.execPath, process.argv[1], 'start', '--daemon']`. For npm installs that became `node dist/index.js start --daemon` and worked. For `bun --compile` standalone binaries, `process.execPath` is the Mercury binary itself and `process.argv[1]` is a bun-virtual `$bunfs/...` path, so the spawn became `mercury "$bunfs/..." start --daemon` — Commander treated the bunfs path as an unknown subcommand, the child died immediately, and `channels.startAll()` (the only place Telegram is started in daemon mode) was never reached.+- **`mercury service install` no longer persists broken commands** — the LaunchAgent plist, systemd unit, and Windows Task Scheduler entry now contain the binary-only invocation (no script path) when running from a standalone binary, so auto-start on boot works end-to-end.+- **Telegram now comes online in background mode for standalone-binary users** — direct consequence of the daemon fix.++### Internal++- New `isStandaloneBinary()` / `buildDaemonSpawnArgs()` helpers in `src/cli/daemon.ts` plus `getServiceLaunchArgs()` in `src/cli/service.ts`, wired through every OS installer. Detection uses `process.versions.bun`, `$bunfs` / `~BUN` markers in `argv[1]`, and the `execPath` basename — so `node`, `bun <script>`, and standalone `mercury` invocations all do the right thing.++### Migration from 1.1.11++No changes required. After upgrading, run `mercury restart` (or `mercury service uninstall && mercury service install` if you had the service installed under 1.1.11 with the broken command persisted).+## 1.1.11 — Token Saver Mode, Skills System & Standalone BinariesThe biggest release since the 1.1.x line started. Adds a full **Skill System**, a **Token Saver Mode** for cheaper sessions, **standalone binaries** for users who don't want npm, and a redesigned bottom status bar with per-step spinners.diff --git a/RELEASE.md b/RELEASE.mdindex 4d08f64e..c753c02a 100644--- a/RELEASE.md+++ b/RELEASE.md@@ -1,53 +1,58 @@-# Release v1.1.11+# Release v1.1.12-## ☿ Mercury Agent v1.1.11+## ☿ Mercury Agent v1.1.12 — Daemon hotfix-**Token Saver Mode, full Skill System, and standalone binaries.**+Hotfix on top of [v1.1.11](https://github.com/cosmicstack-labs/mercury-agent/releases/tag/v1.1.11). The standalone single-file binaries introduced in 1.1.11 could not start in the background — which meant Telegram never came online for anyone who installed Mercury via the one-line installer (the recommended path for web servers).-The biggest release since the 1.1.x line began — Mercury now ships as a single executable on every major OS, learns new tricks via user-defined skills, and gives you a live status bar with token usage at the bottom of every session.+### What Was Broken-### What's New+`src/cli/daemon.ts` spawned the daemon child as:-- **Token Saver Mode** (#69) — opt-in mode that aggressively trims session context so long-running agents don't bleed tokens. Pairs with a redesigned bottom status bar showing provider, model, and live token usage, plus per-step spinners (one per tool call) instead of a single global one.-- **Skill System** (#67) — Mercury can now load user-defined behaviors as markdown files in `~/.mercury/skills/`. Skills get routed to on demand based on keyword/semantic match and inject their instructions only when relevant.-- **Screenshot skill** — built-in skill for capturing website screenshots with configurable viewport and dark/light mode support.-- **Standalone binaries** (#61) — `mercury` now ships as a single executable for:- - macOS arm64 / x64- - Linux x64 / arm64- - Windows x64-- One-line installers are available per OS; no Node runtime required. The install widget on [mercuryagent.sh](https://mercuryagent.sh) detects your platform automatically.-- **Domain migration** — Mercury's home is now [mercuryagent.sh](https://mercuryagent.sh) (was `mercury.cosmicstack.org`).-- **Chinese translations** for README, ARCHITECTURE, and CHANGELOG (#53).+```+spawn(process.execPath, [process.argv[1], 'start', '--daemon'], ...)+```-### Bug Fixes+- **npm install:** resolved to `node dist/index.js start --daemon` ✅+- **Standalone binary** (`bun build --compile`): resolved to `mercury "/$bunfs/root/.../index.js" start --daemon` — Commander treated the bun-virtual path as an unknown subcommand, the child exited immediately, and `channels.startAll()` (the only place Telegram's `bot.start()` runs in daemon mode) was never reached.-- **Skill routing no longer fans out to 10 skills** (#68) — when the router is genuinely uncertain, you now get a clean numbered picker (`#1`, `#2`, …) instead of every weakly-matching skill firing at once.-- **No more spurious ambiguity prompts** from incidental keyword overlap. The matcher now requires real signal before asking you to disambiguate.-- **Release asset names aligned with published binaries** (#63) — fixes one-line installer scripts that were pointing at the wrong filenames in earlier GitHub releases.-- **Shell permission guard now checks each segment independently** (#48) — addresses a reported advisory where a combined shell pattern could slip a disallowed command past the permission check when chained with `;`, `&&`, or `|`.+`mercury service install` had the same flaw and was persisting that broken command into the LaunchAgent plist / systemd unit / Task Scheduler entry, so the failure also survived reboots.-### Maintenance+### Fixed-- Removed the `anonymous-file-uploader` skill — no longer needed.-- `pino` upgraded 9.14.0 → ^10.3.1 (#51).-- Spinner polish, docs refreshes, and a cleaner status line throughout the TUI.+- **Daemon now spawns correctly from both install paths** — new `isStandaloneBinary()` detection in `src/cli/daemon.ts` chooses between `[node, script, 'start', '--daemon']` (npm) and `[mercury, 'start', '--daemon']` (standalone binary). Detection looks at `process.versions.bun`, `$bunfs` / `~BUN` markers in `argv[1]`, and the `execPath` basename, so `node`, `bun <script>` (dev), and standalone `mercury` all do the right thing.+- **System-service files generated correctly for standalone installs** — macOS LaunchAgent `ProgramArguments`, Linux systemd `ExecStart=`, and Windows `schtasks /tr` now use the binary-only invocation when running from a compiled binary.+- **Telegram comes online again in background mode** — direct consequence of the daemon fix.-### Install / Upgrade+### Upgrade**npm:**```-npm install -g @cosmicstack/[email protected]+npm install -g @cosmicstack/[email protected]+mercury restart+```++**Standalone binary:** re-run the one-line installer from [mercuryagent.sh](https://mercuryagent.sh), then:+```+mercury restart```-**Standalone binary:** download from the release assets below (checksums in `checksums.txt`), or use the one-line installer from [mercuryagent.sh](https://mercuryagent.sh).+If you had `mercury service install` set up under 1.1.11 (so the broken command got written into your service file), reinstall it:+```+mercury service uninstall+mercury service install+```-### Migration from v1.1.9+### Verifying The Fix-No breaking changes. Skill System and Token Saver Mode are both opt-in. Existing configs, providers, and `~/.mercury/` data carry over unchanged.+```+mercury start+mercury status # should show a live PID+mercury logs # should show "Mercury is live (daemon mode)" and Telegram polling+```-> `1.1.10` was skipped to keep numbering aligned across publish channels.+### Files Touched----+- `src/cli/daemon.ts` — `isStandaloneBinary()` + `buildDaemonSpawnArgs()`; `ensureDaemonRunning()` uses them.+- `src/cli/service.ts` — `getServiceLaunchArgs()` wired into macOS / Linux / Windows installers.-**Full Changelog**: https://github.com/cosmicstack-labs/mercury-agent/compare/v1.1.9...v1.1.11+**Full Changelog**: https://github.com/cosmicstack-labs/mercury-agent/compare/v1.1.11...v1.1.12diff --git a/package.json b/package.jsonindex 59288b45..a23de4c4 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "@cosmicstack/mercury-agent",- "version": "1.1.11",+ "version": "1.1.12","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/daemon.ts b/src/cli/daemon.tsindex de1a6675..d553868e 100644--- a/src/cli/daemon.ts+++ b/src/cli/daemon.ts@@ -5,6 +5,44 @@ import process from 'node:process';import chalk from 'chalk';import { getMercuryHome } from '../utils/config.js';+/**+ * Detect whether Mercury is running from a standalone, single-file binary+ * (produced by `bun build --compile`). In that case `process.execPath` IS+ * the Mercury binary and `process.argv[1]` is a bun-virtual path (e.g.+ * `/$bunfs/root/...`) that must NOT be forwarded to a child process.+ */+export function isStandaloneBinary(): boolean {+ // Bun sets this flag whenever the runtime is bun (including --compile output).+ const isBunRuntime = typeof (process.versions as any).bun === 'string';+ if (!isBunRuntime) return false;++ const arg1 = process.argv[1];+ if (!arg1) return true;+ // Bun's embedded fs path markers (POSIX `$bunfs`, Windows `B:/~BUN/`).+ if (arg1.includes('$bunfs') || arg1.includes('/~BUN/') || arg1.includes('\\~BUN\\')) return true;+ // Heuristic: standalone binary's execPath is not `node`/`bun` (it's the app name).+ const execName = (process.execPath.split(/[\\/]/).pop() || '').toLowerCase();+ if (!execName.startsWith('node') && !execName.startsWith('bun')) return true;+ return false;+}++/**+ * Build the argv used to respawn Mercury as a detached daemon.+ * For standalone binaries we invoke the binary directly (no script path),+ * because Commander treats the bun-virtual path as an unknown subcommand.+ */+export function buildDaemonSpawnArgs(): { command: string; args: string[] } {+ if (isStandaloneBinary()) {+ return { command: process.execPath, args: ['start', '--daemon'] };+ }+ const script = process.argv[1];+ if (!script) {+ // Last-resort guard — caller will surface the error via ensureDaemonRunning().+ throw new Error('Cannot determine Mercury entry script for daemon spawn');+ }+ return { command: process.execPath, args: [script, 'start', '--daemon'] };+}+const PID_FILE = 'daemon.pid';const LOG_FILE = 'daemon.log';@@ -63,7 +101,8 @@ export function ensureDaemonRunning(): { pid: number; fresh: boolean } {const isWin = process.platform === 'win32';const outFd = openSync(logFile, 'a');- const child = spawn(process.execPath, [process.argv[1], 'start', '--daemon'], {+ const { command, args } = buildDaemonSpawnArgs();+ const child = spawn(command, args, {detached: true,stdio: ['ignore', outFd, outFd],env: { ...process.env },diff --git a/src/cli/service.ts b/src/cli/service.tsindex 969dd651..caf034b7 100644--- a/src/cli/service.ts+++ b/src/cli/service.ts@@ -5,6 +5,7 @@ import chalk from 'chalk';import { execSync } from 'node:child_process';import { getMercuryHome } from '../utils/config.js';import { logger } from '../utils/logger.js';+import { isStandaloneBinary } from './daemon.js';const SERVICE_NAME = 'mercury';const SERVICE_DESC = 'Mercury — Soul-Driven AI Agent';@@ -39,6 +40,19 @@ function getDistPath(): string {return join(process.argv[1], '..', '..', 'lib', 'node_modules', '@cosmicstack', 'mercury-agent', 'dist', 'index.js');}+/**+ * Returns the argv pieces a system-service file should use to launch Mercury+ * as a daemon. For npm installs this is `node <dist/index.js> start --daemon`;+ * for standalone (bun --compile) binaries it is just `<mercury> start --daemon`+ * because `process.argv[1]` is a bun-virtual path that must not be persisted.+ */+function getServiceLaunchArgs(): string[] {+ if (isStandaloneBinary()) {+ return [process.execPath, 'start', '--daemon'];+ }+ return [getNodeBinPath(), getDistPath(), 'start', '--daemon'];+}+export function installService(): void {const platform = process.platform;@@ -95,6 +109,9 @@ function installMac(): void {const logPath = join(home, 'daemon.log');const errPath = join(home, 'daemon-error.log');+ const launchArgs = getServiceLaunchArgs();+ const programArgsXml = launchArgs.map((a) => ` <string>${a}</string>`).join('\n');+const plist = `<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0">@@ -103,10 +120,7 @@ function installMac(): void {<string>com.cosmicstack.mercury</string><key>ProgramArguments</key><array>- <string>${nodeBin}</string>- <string>${scriptPath}</string>- <string>start</string>- <string>--daemon</string>+${programArgsXml}</array><key>RunAtLoad</key><true/>@@ -210,13 +224,17 @@ function installLinux(): void {const scriptPath = getDistPath();const home = getMercuryHome();+ const execStart = getServiceLaunchArgs()+ .map((a) => (/[\s"]/.test(a) ? `"${a.replace(/"/g, '\\"')}"` : a))+ .join(' ');+const service = `[Unit]Description=${SERVICE_DESC}After=network.target[Service]Type=simple-ExecStart=${nodeBin} ${scriptPath} start --daemon+ExecStart=${execStart}Restart=on-failureRestartSec=5Environment=PATH=${process.env.PATH || '/usr/local/bin:/usr/bin:/bin'}@@ -316,7 +334,7 @@ function installWindows(): void {const home = getMercuryHome();const logPath = join(home, 'daemon.log');- const cmd = `"${nodeBin}" "${scriptPath}" start --daemon`;+ const cmd = getServiceLaunchArgs().map((a) => `"${a}"`).join(' ');try {execSync(diff --git a/website/docs/releases/1.1.12.mdx b/website/docs/releases/1.1.12.mdxnew file mode 100644index 00000000..aed7a8eb--- /dev/null+++ b/website/docs/releases/1.1.12.mdx@@ -0,0 +1,136 @@+---+title: "v1.1.12 — Daemon Hotfix"+sidebar_label: "v1.1.12"+description: "Hotfix on top of v1.1.11. Standalone binaries can now start in the background, so Telegram works again for users who installed Mercury via the one-line installer."+image: /img/og/1.1.11.png+keywords: [mercury, mercury-agent, hotfix, daemon, telegram, standalone-binary, release, 1.1.12]+---++import Head from '@docusaurus/Head';++<Head>+ <meta property="og:title" content="Mercury Agent v1.1.12 — Daemon Hotfix" />+ <meta property="og:description" content="Standalone binaries can now start in the background. Telegram works again for users who installed Mercury via the one-line installer." />+ <meta property="og:type" content="article" />+ <meta property="og:url" content="https://mercuryagent.sh/docs/releases/1.1.12" />+ <meta property="og:image" content="https://mercuryagent.sh/img/og/1.1.11.png" />+ <meta property="og:site_name" content="Mercury Agent — Soul-driven" />+ <meta name="twitter:card" content="summary_large_image" />+ <meta name="twitter:site" content="@mercuryagent" />+ <meta name="twitter:title" content="Mercury Agent v1.1.12 — Daemon Hotfix" />+ <meta name="twitter:description" content="Daemon now starts correctly from standalone binaries. Telegram is live again." />+ <meta name="twitter:image" content="https://mercuryagent.sh/img/og/1.1.11.png" />+ <link rel="canonical" href="https://mercuryagent.sh/docs/releases/1.1.12" />+</Head>++# v1.1.12 — Daemon Hotfix++> **Hotfix on top of [v1.1.11](/docs/releases/1.1.11).** If you installed Mercury via the one-line installer (or `npm i -g` on a Bun-compiled binary), this release fixes a critical bug where the background daemon refused to start — which also meant Telegram never came online.++If you are running `1.1.11` from a standalone binary on a web server or any always-on box, **upgrade now**.++## What was broken++`mercury start` (and `mercury up`, and `mercury service install`) spawned the daemon child with:++```ts+spawn(process.execPath, [process.argv[1], 'start', '--daemon'], ...)+```++This worked for npm installs (`node dist/index.js start --daemon`) but completely broke standalone Bun-compiled binaries:++- `process.execPath` was `/usr/local/bin/mercury` — the binary itself.+- `process.argv[1]` was a bun-virtual `/$bunfs/root/.../index.js` path that exists only inside the compiled binary's embedded filesystem.++The spawn became `mercury "/$bunfs/root/..." start --daemon`. Commander treated the bunfs path as an unknown subcommand, the child died instantly, the PID file was written and then immediately reaped — and `channels.startAll()` (the only place Telegram's `bot.start()` runs in daemon mode) was never reached.++`mercury service install` had the same flaw, but worse: it persisted that bad command into the macOS LaunchAgent plist / Linux systemd unit / Windows Task Scheduler entry, so the failure also survived reboots.++## Fixed++- **Daemon spawn now picks the right invocation per install channel** — new `isStandaloneBinary()` detection in `src/cli/daemon.ts` looks at `process.versions.bun`, `$bunfs` / `~BUN` markers in `argv[1]`, and the `execPath` basename. It builds:+ - `[node, dist/index.js, 'start', '--daemon']` for npm installs.+ - `[bun, src/index.ts, 'start', '--daemon']` for `bun <script>` dev runs.+ - `[mercury, 'start', '--daemon']` for standalone binaries (no script path).+- **System-service files are correct on both channels** — `getServiceLaunchArgs()` is now wired into the macOS / Linux / Windows installers in `src/cli/service.ts`, so the persisted LaunchAgent plist `ProgramArguments`, systemd `ExecStart=`, and Task Scheduler command all use the binary-only invocation when running standalone. Auto-start on boot works end-to-end again.+- **Telegram comes back online in background mode** — a direct consequence of the daemon fix. No Telegram-specific code changed.++## Who is affected++| Install path | 1.1.11 background mode | 1.1.12 background mode |+|---|---|---|+| `npm i -g @cosmicstack/mercury-agent` | ✅ Works | ✅ Works |+| `curl … install.sh \| sh` (standalone) | ❌ Broken | ✅ Works |+| `irm … install.ps1 \| iex` (standalone) | ❌ Broken | ✅ Works |+| `mercury service install` (standalone) | ❌ Broken (also persists across reboots) | ✅ Works |+| `mercury` from `bun src/index.ts …` (dev) | ✅ Works | ✅ Works |++## Upgrade++**npm:**++```bash+npm install -g @cosmicstack/[email protected]+mercury restart+```++**Standalone (macOS / Linux):**++```bash+curl -fsSL https://mercuryagent.sh/install.sh | bash+mercury restart+```++**Standalone (Windows):**++```powershell+irm https://mercuryagent.sh/install.ps1 | iex+mercury restart+```++**If you had `mercury service install` set up under 1.1.11** (broken command was persisted into the service file), reinstall the service after upgrading the binary:++```bash+mercury service uninstall+mercury service install+```++## Verify++```bash+mercury start+mercury status # should show a live PID+mercury logs # should show "Mercury is live (daemon mode)" and Telegram polling startup+```++If you use Telegram, send a message to your bot — it should respond as before.++## Standalone binaries++Same five targets as v1.1.11:++| OS | Architecture | Binary |+|---|---|---|+| macOS | Apple Silicon | `mercury-macos-arm64` |+| macOS | Intel | `mercury-macos-x64` |+| Linux | x86-64 | `mercury-linux-x64` |+| Linux | ARM64 | `mercury-linux-arm64` |+| Windows | x86-64 | `mercury-win-x64.exe` |++Direct downloads:++- [mercury-macos-arm64](https://github.com/cosmicstack-labs/mercury-agent/releases/download/v1.1.12/mercury-macos-arm64)+- [mercury-macos-x64](https://github.com/cosmicstack-labs/mercury-agent/releases/download/v1.1.12/mercury-macos-x64)+- [mercury-linux-x64](https://github.com/cosmicstack-labs/mercury-agent/releases/download/v1.1.12/mercury-linux-x64)+- [mercury-linux-arm64](https://github.com/cosmicstack-labs/mercury-agent/releases/download/v1.1.12/mercury-linux-arm64)+- [mercury-win-x64.exe](https://github.com/cosmicstack-labs/mercury-agent/releases/download/v1.1.12/mercury-win-x64.exe)+- [checksums.txt](https://github.com/cosmicstack-labs/mercury-agent/releases/download/v1.1.12/checksums.txt)++## Files changed++- `src/cli/daemon.ts` — `isStandaloneBinary()` + `buildDaemonSpawnArgs()`; `ensureDaemonRunning()` uses them.+- `src/cli/service.ts` — `getServiceLaunchArgs()` wired into macOS / Linux / Windows installers.++No new dependencies. No breaking changes. No config migrations.++**Full changelog:** [v1.1.11 → v1.1.12](https://github.com/cosmicstack-labs/mercury-agent/compare/v1.1.11...v1.1.12)diff --git a/website/docs/releases/releases.mdx b/website/docs/releases/releases.mdxindex ab86b160..6ab3fe99 100644--- a/website/docs/releases/releases.mdx+++ b/website/docs/releases/releases.mdx@@ -9,7 +9,8 @@ This section tracks Mercury release notes by version.## Available release notes-- [**v1.1.11 — Skilly Mercury**](/docs/releases/1.1.11) — Skill System, Token Saver Mode, standalone binaries on five OS targets, per-step spinners, screenshot skill.+- [**v1.1.12 — Daemon Hotfix**](/docs/releases/1.1.12) — Critical fix: standalone binaries can now start in the background, restoring Telegram in daemon mode.+- [v1.1.11 — Skilly Mercury](/docs/releases/1.1.11) — Skill System, Token Saver Mode, standalone binaries on five OS targets, per-step spinners, screenshot skill.- [v1.1.9 — Mercury Web, Kanban & Subconscious Memory](/docs/releases/1.1.9)- [v1.1.7](/docs/releases/1.1.7)- [v1.1.6](/docs/releases/1.1.6)diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.tsindex a836b8a6..9ac7e0d8 100644--- a/website/docusaurus.config.ts+++ b/website/docusaurus.config.ts@@ -91,7 +91,7 @@ const config: Config = {},items: [{to: '/docs', label: 'Docs', position: 'left'},- {to: '/docs/releases/1.1.11', label: 'Releases', position: 'left'},+ {to: '/docs/releases/1.1.12', label: 'Releases', position: 'left'},{href: 'https://github.com/cosmicstack-labs/mercury-agent',label: 'GitHub',diff --git a/website/sidebars.ts b/website/sidebars.tsindex 5e32576d..a87c46a6 100644--- a/website/sidebars.ts+++ b/website/sidebars.ts@@ -73,6 +73,7 @@ const sidebars: SidebarsConfig = {collapsed: false,items: ['releases/releases',+ 'releases/1.1.12','releases/1.1.11','releases/1.1.9','releases/1.1.7',