Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["4523"],{61646(e,n,s){s.r(n),s.d(n,{metadata:()=>r,default:()=>u,frontMatter:()=>d,contentTitle:()=>o,toc:()=>c,assets:()=>i});var r=JSON.parse('{"id":"daemon-mode/daemon-mode","title":"Daemon Mode","description":"Mercury runs as a background daemon by default. Telegram and scheduled tasks keep working after you close the terminal.","source":"@site/docs/daemon-mode/background-mode.mdx","sourceDirName":"daemon-mode","slug":"/daemon-mode/daemon-mode","permalink":"/docs/daemon-mode/daemon-mode","draft":false,"unlisted":false,"editUrl":"https://github.com/cosmicstack-labs/mercury-agent/tree/main/website/docs/daemon-mode/background-mode.mdx","tags":[],"version":"current","frontMatter":{"id":"daemon-mode","title":"Daemon Mode"},"sidebar":"docsSidebar","previous":{"title":"In-Chat Commands","permalink":"/docs/cli-commands/in-chat-commands"},"next":{"title":"System Service (Auto-Start on Boot)","permalink":"/docs/daemon-mode/system-service"}}'),t=s(74848),a=s(28453);let d={id:"daemon-mode",title:"Daemon Mode"},o,i={},c=[{value:"Start",id:"start",level:2},{value:"Start in foreground",id:"start-in-foreground",level:2},{value:"The easy way: mercury up",id:"the-easy-way-mercury-up",level:2},{value:"Stop",id:"stop",level:2},{value:"Restart",id:"restart",level:2},{value:"View logs",id:"view-logs",level:2},{value:"Check status",id:"check-status",level:2},{value:"No server? Run it in the cloud",id:"no-server-run-it-in-the-cloud",level:2},{value:"Background Tasks and Workers",id:"background-tasks-and-workers",level:2},{value:"Task IDs",id:"task-ids",level:3},{value:"Shell background tasks",id:"shell-background-tasks",level:3},{value:"Sub-agent workers",id:"sub-agent-workers",level:3},{value:"Persistence",id:"persistence",level:3}];function l(e){let n={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.p,{children:"Mercury runs as a background daemon by default. Telegram and scheduled tasks keep working after you close the terminal."}),"\n",(0,t.jsx)(n.h2,{id:"start",children:"Start"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"mercury start\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Starts Mercury as a background daemon. Spawns a detached child process, writes a PID file to ",(0,t.jsx)(n.code,{children:"~/.mercury/daemon.pid"}),", and redirects output to ",(0,t.jsx)(n.code,{children:"~/.mercury/daemon.log"}),". Stale PID files are automatically cleaned up."]}),"\n",(0,t.jsx)(n.h2,{id:"start-in-foreground",children:"Start in foreground"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"mercury start --foreground\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Runs Mercury attached to your terminal. Useful for debugging or when you want to see output directly. Shorthand: ",(0,t.jsx)(n.code,{children:"mercury start -f"}),"."]}),"\n",(0,t.jsx)(n.h2,{id:"the-easy-way-mercury-up",children:"The easy way: mercury up"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"mercury up\n"})}),"\n",(0,t.jsx)(n.p,{children:"This one command does everything: installs the system service if needed, starts the background daemon, and confirms Mercury is running. If it's already running, it just shows you the PID."}),"\n",(0,t.jsx)(n.h2,{id:"stop",children:"Stop"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"mercury stop\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Sends ",(0,t.jsx)(n.code,{children:"SIGTERM"})," (",(0,t.jsx)(n.code,{children:"process.kill"})," on Windows) to the background process and removes the PID file."]}),"\n",(0,t.jsx)(n.h2,{id:"restart",children:"Restart"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"mercury restart\n"})}),"\n",(0,t.jsx)(n.p,{children:"Stops the running daemon (if any) and starts a fresh one. Useful when something isn't working right and you need a clean restart."}),"\n",(0,t.jsx)(n.h2,{id:"view-logs",children:"View logs"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"mercury logs\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Shows the last 100 lines of ",(0,t.jsx)(n.code,{children:"~/.mercury/daemon.log"}),"."]}),"\n",(0,t.jsx)(n.h2,{id:"check-status",children:"Check status"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"mercury status\n"})}),"\n",(0,t.jsx)(n.p,{children:"Shows whether the daemon is running, its PID, and the log file path."}),"\n",(0,t.jsx)(n.admonition,{title:"Crash recovery",type:"info",children:(0,t.jsx)(n.p,{children:'Background mode includes a watchdog. If Mercury crashes, it restarts automatically with exponential backoff (1s, 1.25s, 1.56s...). After 10 crashes within 60 seconds, it exits to prevent crash loops. Stale PID files are auto-cleaned on startup to prevent "already running" false positives.'})}),"\n",(0,t.jsx)(n.h2,{id:"no-server-run-it-in-the-cloud",children:"No server? Run it in the cloud"}),"\n",(0,t.jsxs)(n.p,{children:["Don't want to manage a daemon, service, or updates yourself? ",(0,t.jsx)(n.a,{href:"https://atomicbot.ai/?utm_source=agent",children:"Atomic Bot"})," offers fully hosted Mercury Code instances \u2014 your agent runs 24/7 on their infrastructure with zero setup, starting at $19/mo. See ",(0,t.jsx)(n.a,{href:"/docs/getting-started/platforms/cloud-instance",children:"Cloud Instance"})," for details."]}),"\n",(0,t.jsx)(n.h2,{id:"background-tasks-and-workers",children:"Background Tasks and Workers"}),"\n",(0,t.jsx)(n.p,{children:"Daemon mode supports async background execution for both shell commands and delegated sub-agent work."}),"\n",(0,t.jsx)(n.h3,{id:"task-ids",children:"Task IDs"}),"\n",(0,t.jsxs)(n.p,{children:["Background tasks use human-friendly IDs like ",(0,t.jsx)(n.code,{children:"swift-fox"}),", ",(0,t.jsx)(n.code,{children:"calm-owl"}),", or ",(0,t.jsx)(n.code,{children:"bright-heron"})," instead of opaque timestamps. There are 2,304 unique combinations (48 adjectives \xd7 48 nouns). If a collision occurs, a numeric suffix is appended."]}),"\n",(0,t.jsx)(n.h3,{id:"shell-background-tasks",children:"Shell background tasks"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["Start with ",(0,t.jsx)(n.code,{children:"/bg <command>"})]}),"\n",(0,t.jsxs)(n.li,{children:["Inspect with ",(0,t.jsx)(n.code,{children:"/bg list"})," and ",(0,t.jsx)(n.code,{children:"/bg <id>"})]}),"\n",(0,t.jsxs)(n.li,{children:["Cancel with ",(0,t.jsx)(n.code,{children:"/bg cancel <id>"})," (or ",(0,t.jsx)(n.code,{children:"/bg stop <id>"}),", ",(0,t.jsx)(n.code,{children:"/bg kill <id>"}),")"]}),"\n",(0,t.jsxs)(n.li,{children:["Cancel all running tasks with ",(0,t.jsx)(n.code,{children:"/bg killall"})," (or ",(0,t.jsx)(n.code,{children:"/bg stopall"}),")"]}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"sub-agent-workers",children:"Sub-agent workers"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["Delegate coding with ",(0,t.jsx)(n.code,{children:"/code agent <task>"})," or ",(0,t.jsx)(n.code,{children:"/bg: <task>"})]}),"\n",(0,t.jsxs)(n.li,{children:["Move active task to worker with ",(0,t.jsx)(n.code,{children:"/bg current"})]}),"\n",(0,t.jsxs)(n.li,{children:["Worker progress/completion is surfaced in the shared background task board (",(0,t.jsx)(n.code,{children:"/bg list"}),")"]}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"persistence",children:"Persistence"}),"\n",(0,t.jsx)(n.p,{children:"Background tasks are persisted to disk and survive daemon restarts. Running tasks that were interrupted by a restart are marked as failed."}),"\n",(0,t.jsx)(n.p,{children:"These workers are designed to keep Mercury responsive while long-running work continues."})]})}function u(e={}){let{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(l,{...e})}):l(e)}},28453(e,n,s){s.d(n,{R:()=>d,x:()=>o});var r=s(96540);let t={},a=r.createContext(t);function d(e){let n=r.useContext(a);return r.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:d(e.components),r.createElement(a.Provider,{value:n},e.children)}}}]);