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.

11.3 KB
Raw Blame
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["4995"],{58852(e,n,s){s.r(n),s.d(n,{metadata:()=>i,default:()=>u,frontMatter:()=>t,contentTitle:()=>d,toc:()=>o,assets:()=>c});var i=JSON.parse('{"id":"getting-started/build-from-source","title":"Build From Source","description":"Mercury can be built from source two ways:","source":"@site/docs/getting-started/build-from-source.mdx","sourceDirName":"getting-started","slug":"/getting-started/build-from-source","permalink":"/docs/getting-started/build-from-source","draft":false,"unlisted":false,"editUrl":"https://github.com/cosmicstack-labs/mercury-agent/tree/main/website/docs/getting-started/build-from-source.mdx","tags":[],"version":"current","frontMatter":{"id":"build-from-source","title":"Build From Source"},"sidebar":"docsSidebar","previous":{"title":"Starting Mercury","permalink":"/docs/getting-started/starting"},"next":{"title":"Full Command Reference","permalink":"/docs/cli-commands/cli-commands"}}'),r=s(74848),l=s(28453);let t={id:"build-from-source",title:"Build From Source"},d,c={},o=[{value:"Prerequisites",id:"prerequisites",level:2},{value:"Standard Build",id:"standard-build",level:2},{value:"Standalone Executable",id:"standalone-executable",level:2},{value:"Quick start",id:"quick-start",level:3},{value:"All build commands",id:"all-build-commands",level:3},{value:"Output layout",id:"output-layout",level:3},{value:"Cross-compilation",id:"cross-compilation",level:3},{value:"macOS code signing",id:"macos-code-signing",level:3},{value:"Troubleshooting",id:"troubleshooting",level:2}];function a(e){let n={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,l.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"Mercury can be built from source two ways:"}),"\n",(0,r.jsxs)(n.ol,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Standard build"})," \u2014 produces the regular ESM bundle in ",(0,r.jsx)(n.code,{children:"dist/"}),", the same artifact published to npm. Good for local development, contributions, and ",(0,r.jsx)(n.code,{children:"npm link"}),"."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Standalone executable"})," \u2014 produces a single self-contained binary that embeds the JS runtime and the entire Mercury bundle. End-users do ",(0,r.jsx)(n.strong,{children:"not"})," need Node.js installed."]}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"prerequisites",children:"Prerequisites"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"Node.js \u2265 20"})," \u2014 required for the build toolchain."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsxs)(n.strong,{children:[(0,r.jsx)(n.a,{href:"https://bun.sh",children:"Bun"})," \u2265 1.3"]})," \u2014 only needed if you're building standalone binaries."]}),"\n"]}),"\n",(0,r.jsx)(n.p,{children:"Install Bun:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"curl -fsSL https://bun.sh/install | bash\n"})}),"\n",(0,r.jsx)(n.h2,{id:"standard-build",children:"Standard Build"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"git clone https://github.com/cosmicstack-labs/mercury-agent.git\ncd mercury-agent\nnpm install\nnpm run build           # tsup + post-build (UI, static assets, wasm)\nnpm start               # runs node dist/index.js\n"})}),"\n",(0,r.jsxs)(n.p,{children:["To use your local build as the global ",(0,r.jsx)(n.code,{children:"mercury"})," command:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm link\nmercury --help\n"})}),"\n",(0,r.jsx)(n.h2,{id:"standalone-executable",children:"Standalone Executable"}),"\n",(0,r.jsxs)(n.p,{children:["Mercury uses ",(0,r.jsx)(n.a,{href:"https://bun.sh/docs/bundler/executables",children:(0,r.jsx)(n.code,{children:"bun build --compile"})})," to embed the entire bundle into a single platform-native binary. The resulting file runs on machines with ",(0,r.jsx)(n.strong,{children:"no Node.js, no Bun, and no dependencies"})," installed."]}),"\n",(0,r.jsx)(n.h3,{id:"quick-start",children:"Quick start"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm install\nnpm run build:bin       # builds the binary for your current OS/arch\n./release/v1.1.9/mercury-macos-arm64 --help\n"})}),"\n",(0,r.jsx)(n.h3,{id:"all-build-commands",children:"All build commands"}),"\n",(0,r.jsxs)(n.table,{children:[(0,r.jsx)(n.thead,{children:(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.th,{children:"Command"}),(0,r.jsx)(n.th,{children:"Targets"}),(0,r.jsx)(n.th,{children:"Behavior on existing build"})]})}),(0,r.jsxs)(n.tbody,{children:[(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"npm run build:bin"})}),(0,r.jsx)(n.td,{children:"host only"}),(0,r.jsx)(n.td,{children:"skip if already built"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"npm run build:bin:all"})}),(0,r.jsx)(n.td,{children:"all 5 platforms"}),(0,r.jsx)(n.td,{children:"skip per-target"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"npm run build:bin:force"})}),(0,r.jsx)(n.td,{children:"host only"}),(0,r.jsx)(n.td,{children:"overwrite"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"npm run build:bin:all:force"})}),(0,r.jsx)(n.td,{children:"all 5 platforms"}),(0,r.jsx)(n.td,{children:"overwrite"})]})]})]}),"\n",(0,r.jsxs)(n.p,{children:["Supported targets for ",(0,r.jsx)(n.code,{children:"--all"}),":"]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:"macOS arm64 (Apple Silicon)"}),"\n",(0,r.jsx)(n.li,{children:"macOS x64 (Intel)"}),"\n",(0,r.jsx)(n.li,{children:"Linux x64"}),"\n",(0,r.jsx)(n.li,{children:"Linux arm64"}),"\n",(0,r.jsx)(n.li,{children:"Windows x64"}),"\n"]}),"\n",(0,r.jsx)(n.h3,{id:"output-layout",children:"Output layout"}),"\n",(0,r.jsxs)(n.p,{children:["The build script reads the version from ",(0,r.jsx)(n.code,{children:"package.json"})," and writes binaries into a versioned subfolder. Older builds are ",(0,r.jsx)(n.strong,{children:"never overwritten"})," \u2014 you can keep many versions side-by-side."]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:"release/\n\u251C\u2500\u2500 latest                       \u2192 symlink to the most-recent version\n\u251C\u2500\u2500 v1.1.9/\n\u2502   \u251C\u2500\u2500 mercury-macos-arm64\n\u2502   \u251C\u2500\u2500 mercury-macos-x64\n\u2502   \u251C\u2500\u2500 mercury-linux-x64\n\u2502   \u251C\u2500\u2500 mercury-linux-arm64\n\u2502   \u251C\u2500\u2500 mercury-win-x64.exe\n\u2502   \u2514\u2500\u2500 checksums.txt            (SHA-256 for every binary in the folder)\n\u2514\u2500\u2500 v1.2.0/\n    \u2514\u2500\u2500 ...\n"})}),"\n",(0,r.jsxs)(n.p,{children:["Bump ",(0,r.jsx)(n.code,{children:"version"})," in ",(0,r.jsx)(n.code,{children:"package.json"})," before building and the script automatically creates a new folder. If a binary for the current version+target already exists, the script ",(0,r.jsx)(n.strong,{children:"skips"})," it (printing ",(0,r.jsx)(n.code,{children:"\u21B7 skip (already built)"}),") unless you pass ",(0,r.jsx)(n.code,{children:"--force"}),"."]}),"\n",(0,r.jsx)(n.p,{children:"Verify integrity with the generated checksums:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"cd release/v1.1.9\nshasum -a 256 -c checksums.txt\n# mercury-macos-arm64: OK\n"})}),"\n",(0,r.jsx)(n.h3,{id:"cross-compilation",children:"Cross-compilation"}),"\n",(0,r.jsxs)(n.p,{children:["Bun ships its own runtime per target, so you can build ",(0,r.jsx)(n.strong,{children:"all five platforms from any one host"})," (e.g. produce a Windows ",(0,r.jsx)(n.code,{children:".exe"})," from your Mac):"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"npm run build:bin:all\n"})}),"\n",(0,r.jsxs)(n.p,{children:["Native node modules can't cross-compile, but Mercury's only native dep (",(0,r.jsx)(n.code,{children:"better-sqlite3"}),") is ",(0,r.jsx)(n.strong,{children:"optional"})," \u2014 at runtime the binary falls back to ",(0,r.jsx)(n.code,{children:"sql.js"})," (pure JS + wasm). Cross-compiled binaries are fully functional."]}),"\n",(0,r.jsx)(n.h3,{id:"macos-code-signing",children:"macOS code signing"}),"\n",(0,r.jsx)(n.p,{children:"Unsigned binaries trigger Gatekeeper on first launch. For local use, right-click \u2192 Open once and macOS will remember the choice. For distribution:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:'codesign --sign "Developer ID Application: Your Name" release/v1.1.9/mercury-macos-arm64\nxcrun notarytool submit release/v1.1.9/mercury-macos-arm64 --apple-id ... --wait\n'})}),"\n",(0,r.jsx)(n.admonition,{title:"Why Bun and not pkg / Node SEA?",type:"tip",children:(0,r.jsxs)(n.p,{children:["Mercury's dependency graph includes ESM modules with top-level ",(0,r.jsx)(n.code,{children:"await"})," (",(0,r.jsx)(n.code,{children:"ink"}),", ",(0,r.jsx)(n.code,{children:"yoga-layout"}),"). Both ",(0,r.jsx)(n.code,{children:"pkg"})," and Node.js Single Executable Applications require CommonJS entry points and can't transform top-level await. Bun runs ESM natively and embeds its own runtime, so it sidesteps the whole problem."]})}),"\n",(0,r.jsx)(n.h2,{id:"troubleshooting",children:"Troubleshooting"}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:(0,r.jsx)(n.code,{children:"bun: command not found"})})," \u2014 install Bun with ",(0,r.jsx)(n.code,{children:"curl -fsSL https://bun.sh/install | bash"}),", then either restart your shell or use the explicit path ",(0,r.jsx)(n.code,{children:"~/.bun/bin/bun"}),"."]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:(0,r.jsx)(n.code,{children:"ERROR: dist/index.js not found"})})," \u2014 the bin script depends on the standard build. The ",(0,r.jsx)(n.code,{children:"build:bin"})," npm script chains both; if you ran the bin script directly, prefix with ",(0,r.jsx)(n.code,{children:"npm run build"}),"."]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"Binary silently exits with code 0"})," \u2014 usually means the ",(0,r.jsx)(n.code,{children:"package.json"})," version lookup failed. The build pipeline injects the version at compile time via ",(0,r.jsx)(n.code,{children:"tsup --define"}),". If you've modified the entry file, make sure the ",(0,r.jsx)(n.code,{children:"pkgVersion"})," fallback path remains intact (see ",(0,r.jsx)(n.code,{children:"src/index.ts"}),")."]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsxs)(n.strong,{children:["Stale ",(0,r.jsx)(n.code,{children:"release/latest"})," symlink"]})," \u2014 re-running any ",(0,r.jsx)(n.code,{children:"build:bin"})," command repairs the symlink to point at the current ",(0,r.jsx)(n.code,{children:"package.json"})," version."]})]})}function u(e={}){let{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(a,{...e})}):a(e)}},28453(e,n,s){s.d(n,{R:()=>t,x:()=>d});var i=s(96540);let r={},l=i.createContext(r);function t(e){let n=i.useContext(l);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:t(e.components),i.createElement(l.Provider,{value:n},e.children)}}}]);