The Problem
Developers need an AI agent that can read files, run commands, and fetch URLs without silently executing anything. Existing tools either expose too much power or require manual scripting. The core pain is a safe, permission‑controlled runtime that remembers user preferences and enforces token budgets.
What This Does
@cosmicstack/mercury-agent delivers a soul‑driven agent that runs 24/7 from CLI, Telegram, or Web.
- Permission‑hardened tools: the shell blocklist lives in
src/capabilities/shell/index.tsand is the single source of truth for what commands may run. - Second Brain: a SQLite database (
src/database/index.ts) stores 10 structured memory types with full‑text search. - Token‑aware: daily budgets and the
/budgetcommand are handled insrc/capabilities/interaction/index.ts. - Extensible skills: community skills are installed under
~/.mercury/skills/and loaded bysrc/capabilities/index.ts. - Daemon mode:
mercury upinstalls and starts a system service; the service logic lives insrc/daemon.ts.
The agent’s personality is defined by user‑editable markdown files (soul.md, persona.md) located in the user’s config directory.
How It Is Wired
Entry point mercury (bin defined in package.json) resolves to dist/cli/mercury.js, which imports src/cli/index.ts. src/cli/index.ts parses arguments, then calls runCommand in src/commands/index.ts.
Command routing runCommand dispatches to src/capabilities/index.ts.
index.tsloads the appropriate capability module (filesystem,shell,interaction) based on the command.- Each capability exports
execute(e.g.,filesystem.execute(filePath)orshell.execute(command)).
Side effects
- File read/write →
src/capabilities/filesystem/index.tsupdates the SQLite DB viasrc/database/operations.ts. - Shell execution →
src/capabilities/shell/index.tschecks the blocklist, then runschild_process.execand streams output back to the CLI. - Interaction commands (e.g.,
/budget) modify the token ledger insrc/capabilities/interaction/index.ts, which writes to the database.
Wider blast radius src/capabilities/index.ts is the hub; changes here affect every command. The SQLite schema in src/database/schema.sql is the only external dependency on the filesystem.
How To Use It
Setup
# Standalone binary (no Node required)
curl -fsSL https://mercuryagent.sh/install.sh | sh
# or via npm (Node 20+)
npx @cosmicstack/mercury-agent
# or global install
npm i -g @cosmicstack/mercury-agent
The first run triggers mercury doctor, which creates ~/.mercury/config.json from .env.example.
Configuration
~/.mercury/config.jsonholds API keys, token limits, and permission mode.- The user’s soul files (
soul.md,persona.md) live in the same directory.
Running
# Interactive CLI
mercury
# Daemon mode
mercury up
The CLI launches the Ink TUI (src/ui/ink.ts) and then hands control to the command loop in src/cli/loop.ts.
Real‑World Use
A team uses Mercury as a nightly build monitor. A build-monitor skill watches the CI log directory, and when a new log is written, filesystem.execute triggers a shell command to parse the log, update the second brain, and send a Telegram message with the result.
// build-monitor skill (auto‑loaded from ~/.mercury/skills)
import { watch } from 'fs';
watch('/var/log/ci', async () => {
const output = await shell.execute('parse-ci-log /var/log/ci/latest.log');
await db.update('build', { status: output });
telegram.send('Build completed: ' + output);
});
Code Health & Issues
- Tests: 77 test files under
tests/. - CI:
/.github/workflows/ci.ymlruns lint, type‑check, and tests on every push. - License: MIT (
LICENSE). - No structural red flags: all major components have unit tests, and the build pipeline is defined in
package.jsonandui/vite.config.ts. - Missing docs: while
docs/contains comprehensive HTML, Markdown documentation for the internal API is sparse.
The Bottom Line
Mercury offers a well‑structured, permission‑controlled AI agent with persistent memory and token budgeting. Its TypeScript codebase is heavily tested, and the CLI is straightforward to extend with new skills. Teams needing a safe, always‑on agent for CI/CD or personal automation will find it useful, though the internal API docs could be expanded for easier contribution.