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.ts and 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 /budget command are handled in src/capabilities/interaction/index.ts.
  • Extensible skills: community skills are installed under ~/.mercury/skills/ and loaded by src/capabilities/index.ts.
  • Daemon mode: mercury up installs and starts a system service; the service logic lives in src/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.ts loads the appropriate capability module (filesystem, shell, interaction) based on the command.
  • Each capability exports execute (e.g., filesystem.execute(filePath) or shell.execute(command)).

Side effects

  • File read/write → src/capabilities/filesystem/index.ts updates the SQLite DB via src/database/operations.ts.
  • Shell execution → src/capabilities/shell/index.ts checks the blocklist, then runs child_process.exec and streams output back to the CLI.
  • Interaction commands (e.g., /budget) modify the token ledger in src/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.json holds 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.yml runs 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.json and ui/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.