MoltBrain
Long-term memory layer for OpenClaw & MoltBook agents that learns and recalls your project context automatically.
Safety scan
A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.
Check it deeper on your machine
Its scripts were only partly scanned.
As a Claude Code plugin, install it and then ask Claude Code:
/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/nhevers/MoltBrain with scanskillsafety
Or from a terminal, clone it and run it:
git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/nhevers/MoltBrain'
It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.
Badge for your README
Markdown
[](/listings/nhevers--moltbrain)HTML
<a href="/listings/nhevers--moltbrain"><img src="/api/listings/nhevers--moltbrain/badge.svg" alt="findsafeskills safety rating" /></a>Install
Install instructions from the README
As written by the repo's author. findsafeskills has not verified these steps.
<p align="center">
╔══════════════════════════════════════════════════════════════════════╗ ║ ║ ║ Step 1 /plugin marketplace add nhevers/moltbrain ║ ║ Step 2 /plugin install moltbrain ║ ║ ║ ╚══════════════════════════════════════════════════════════════════════╝
</p>
<p align="center"><em>That's it. MoltBrain starts working automatically.</em></p>
---
<br>
What was scanned
The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.
.claude-plugin/marketplace.json · Manifest · 18 lines
View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)
- {
- "name": "nhevers",
- "owner": {
- "name": "nhevers"
- },
- "metadata": {
- "description": "Plugins by nhevers",
- "homepage": "https://github.com/nhevers/claude-recall"
- },
- "plugins": [
- {
- "name": "claude-recall",
- "version": "9.0.9",
- "source": "./plugin",
- "description": "Persistent memory system for Claude Code - context compression across sessions"
- }
- ]
- }
README.md · README · 468 lines
View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)
- <p align="center">
- <img width="1344" height="768" alt="Untitled design (32)" src="https://github.com/user-attachments/assets/03483342-0950-4d80-8bd2-423cd644b6ba" />
- </p>
- <p align="center">
- </p>
- <p align="center">
- <strong>Long-term memory layer for OpenClaw, MoltBook & Claude Code that learns and recalls your project context automatically.</strong>
- </p>
- <p align="center">
- <a href="#-quick-install">Install</a> •
- <a href="#-features">Features</a> •
- <a href="#-how-it-works">How It Works</a> •
- <a href="#-storage-dapp">Storage</a> •
- <a href="#-virtuals-protocol-integration">Virtuals</a> •
- <a href="#-openclaw-integration">OpenClaw</a> •
- <a href="#%EF%B8%8F-configuration">Config</a> •
- <a href="#-api">API</a>
- </p>
- ---
- <br>
- ## ⚡ Quick Install
- <p align="center">
- ```
- ╔══════════════════════════════════════════════════════════════════════╗
- ║ ║
- ║ Step 1 /plugin marketplace add nhevers/moltbrain ║
- ║ Step 2 /plugin install moltbrain ║
- ║ ║
- ╚══════════════════════════════════════════════════════════════════════╝
- ```
- </p>
- <p align="center"><em>That's it. MoltBrain starts working automatically.</em></p>
- ---
- <br>
- ## 🧠 What It Does
- ```
- ╭──────────────────────────────────────────────────────────────────────────────╮
- │ │
- │ ┌─────────────────┐ ┌─────────────────┐ │
- │ │ SESSION #1 │ │ SESSION #47 │ │
- │ │─────────────────│ │─────────────────│ │
- │ │ │ │ │ │
- │ │ "Set up auth │ │ "Add password │ │
- │ │ with OAuth" │ │ reset flow" │ │
- │ │ │ │ │ │
- │ └────────┬────────┘ └────────┬────────┘ │
- │ │ │ │
- │ │ Claude discovers: │ Claude remembers: │
- │ │ • OAuth2 + PKCE flow │ • Your auth setup │
- │ │ • JWT with 1hr expiry │ • Token structure │
- │ │ • bcrypt cost factor 12 │ • Security choices │
- │ │ │ │
- │ ▼ ▲ │
- │ ┌────────────────┐ ┌────────────────┐ │
- │ │ CAPTURE │ ──────────────────► │ INJECT │ │
- │ │ & LEARN │ MEMORY │ & RECALL │ │
- │ └────────────────┘ └────────────────┘ │
- │ │
- ╰──────────────────────────────────────────────────────────────────────────────╯
- ```
- <br>
- ---
- ## ✨ Features
- ```
- +-------------------------+-------------------------+-------------------------+
- | | | |
- | OBSERVATIONS | SMART SEARCH | WEB VIEWER |
- | ---------------- | ---------------- | ---------------- |
- | Auto-captures | Semantic search | Browse history |
- | discoveries, | via MCP tools | at localhost |
- | decisions & code | finds context | :37777 |
- | | | |
- +-------------------------+-------------------------+-------------------------+
- | | | |
- | ANALYTICS | TAGS & FILTERS | FAVORITES |
- | ---------------- | ---------------- | ---------------- |
- | Track tokens, | Organize with | Bookmark your |
- | sessions, and | custom tags & | most important |
- | concept trends | smart filters | observations |
- | | | |
- +-------------------------+-------------------------+-------------------------+
- | | | |
- | EXPORT | THEMES | SHORTCUTS |
- | ---------------- | ---------------- | ---------------- |
- | JSON, CSV, or | Dark & light | Full keyboard |
- | Markdown with | mode with | navigation in |
- | custom templates | custom themes | the web viewer |
- | | | |
- +-------------------------+-------------------------+-------------------------+
- ```
- <br>
- ---
- ## 🔧 How It Works
- ```
- ╔═══════════════════════════════════╗
- ║ CLAUDE CODE SESSION ║
- ╚═══════════════╤═══════════════════╝
- │
- ┌────────────────────┼────────────────────┐
- │ │ │
- ▼ ▼ ▼
- ╔════════════════╗ ╔════════════════╗ ╔════════════════╗
- ║ SessionStart ║ ║ PostToolUse ║ ║ Stop ║
- ║────────────────║ ║────────────────║ ║────────────────║
- ║ Inject context ║ ║ Capture output ║ ║ Generate ║
- ║ from memory ║ ║ extract facts ║ ║ summary ║
- ╚═══════╤════════╝ ╚═══════╤════════╝ ╚═══════╤════════╝
- │ │ │
- └────────────────────┼────────────────────┘
- │
- ╔══════════════╧══════════════╗
- ║ WORKER SERVICE ║
- ║ http://localhost:37777 ║
- ╚══════════════╤══════════════╝
- │
- ┌─────────────────────────┼─────────────────────────┐
- │ │ │
- ▼ ▼ ▼
- ╔════════════════╗ ╔════════════════╗ ╔════════════════╗
- ║ SQLite ║ ║ ChromaDB ║ ║ Web Viewer ║
- ║ Database ║ ║ Vector Search ║ ║ UI ║
- ║────────────────║ ║────────────────║ ║────────────────║
- ║ Observations ║ ║ Semantic ║ ║ Timeline ║
- ║ Summaries ║ ║ similarity ║ ║ Search ║
- ║ Sessions ║ ║ matching ║ ║ Analytics ║
- ╚════════════════╝ ╚════════════════╝ ╚════════════════╝
- ```
- <br>
- ---
- ## ⚙️ Configuration
- Settings stored in `~/.moltbrain/settings.json`:
- ```
- ┌──────────────────────────────────────┬─────────┬────────────────────────────┐
- │ SETTING │ DEFAULT │ DESCRIPTION │
- ├──────────────────────────────────────┼─────────┼────────────────────────────┤
- │ MOLTBRAIN_WORKER_PORT │ 37777 │ Worker service port │
- ├──────────────────────────────────────┼─────────┼────────────────────────────┤
- │ MOLTBRAIN_CONTEXT_OBSERVATIONS │ 50 │ Max observations to inject │
- ├──────────────────────────────────────┼─────────┼────────────────────────────┤
- │ MOLTBRAIN_PROVIDER │ claude │ AI provider for summaries │
- ├──────────────────────────────────────┼─────────┼────────────────────────────┤
- │ MOLTBRAIN_PRUNE_DAYS │ 0 │ Auto-prune (0 = disabled) │
- ├──────────────────────────────────────┼─────────┼────────────────────────────┤
- │ MOLTBRAIN_THEME │ system │ UI theme (dark/light/sys) │
- ├──────────────────────────────────────┼─────────┼────────────────────────────┤
- │ MOLTBRAIN_LOG_LEVEL │ info │ Logging verbosity level │
- └──────────────────────────────────────┴─────────┴────────────────────────────┘
- ```
- <br>
- ---
- ## 💻 CLI Commands
- ```bash
- moltbrain stats # Show memory statistics
- moltbrain export # Export to markdown
- moltbrain tag <id> <t> # Tag an observation
- moltbrain prune # Manual cleanup
- moltbrain search <q> # Search observations
- ```
- <br>
- ---
- ## 📁 Project Structure
- ```
- moltbrain/
- │
- ├── 📊 benchmarks/ Performance tests
- ├── 🎨 contrib/ Community modes & themes
- ├── 📚 docs/ Documentation
- ├── 📖 examples/ Usage examples & guides
- │
- ├── 🔌 extension/
- │ ├── profiles/ Observation modes
- │ ├── runtime/ Worker scripts
- │ ├── themes/ UI themes (dark/light)
- │ ├── snippets/ Code snippets
- │ └── templates/ Summary templates
- │
- ├── 🌍 locales/ i18n (en, es, fr)
- ├── 🗄️ migrations/ Database migrations
- ├── 📋 schemas/ JSON validation schemas
- ├── 🛠️ scripts/ Build & utility scripts
- │
- ├── 💻 src/
- │ ├── analytics/ Token & session tracking
- │ ├── cache/ Query & context caching
- │ ├── core/ Core engine
- │ ├── export/ JSON/CSV/MD exporters
- │ ├── favorites/ Bookmark system
- │ ├── filters/ Date/type/project filters
- │ ├── formatters/ Output formatters
- │ ├── mcp/ MCP server for OpenClaw & MoltBook
- │ ├── shortcuts/ Keyboard shortcuts
- │ ├── themes/ Theme system
- │ └── validators/ Input validation
- │
- ├── 🦞 integrations/
- │ └── clawd/ Clawd extension & skill
- │
- ├── 📝 templates/ Export templates
- ├── 🧪 tests/ Test suites
- └── 🔧 tools/ CLI utilities
- ```
- <br>
- ---
- ## 🔌 API
- The worker exposes a REST API at `http://localhost:37777`:
- ```bash
- # Health check
- curl http://localhost:37777/health
- # Search observations
- curl "http://localhost:37777/api/search?q=authentication"
- # Get timeline
- curl "http://localhost:37777/api/timeline?project=my-app&days=7"
- # Export data
- curl "http://localhost:37777/api/export?format=json" > backup.json
- # Get statistics
- curl "http://localhost:37777/api/stats"
- ```
- <br>
- ---
- ## 🗄️ Storage Dapp
- Persistent, Postgres-backed storage for agents and apps. Live at **[app.moltbrain.dev/storage](https://app.moltbrain.dev/storage)**.
- ```
- +-----------------------------------------------------------------------------+
- | |
- | BLOB STORAGE Content-addressed JSON blobs via SHA-256 |
- | ---------- Store and retrieve data by hash. $0.01 per request. |
- | |
- | MEMORY SLOTS Named key-value slots for agent state |
- | ---------- Allocate, write, read. Persistent across sessions. |
- | |
- | AGENT VAULT Per-wallet scoping with label badges |
- | ---------- Connect the same wallet your agents use. |
- | Browse, view, and delete what they stored. |
- | |
- +-----------------------------------------------------------------------------+
- ```
- All endpoints are paid via [x402](https://www.x402.org) micropayments ($0.01 USDC on Base). Data is scoped per wallet, backed by Postgres, and survives redeploys.
- Agents can tag stored data with a `label` (e.g. `"openclaw_session"`, `"virtuals_agent"`) so the vault shows what stored each item.
- ```bash
- # Store a blob
- curl -X POST https://app.moltbrain.dev/api/x402/store \
- -H "X-PAYMENT: <x402_header>" \
- -d '{"data": {"key": "value"}, "label": "my_agent"}'
- # List your blobs
- curl https://app.moltbrain.dev/api/x402/list/blobs \
- -H "X-PAYMENT: <x402_header>"
- # Full catalog
- curl https://app.moltbrain.dev/api/x402/catalog
- ```
- <br>
- ---
- ## 🎮 Virtuals Protocol Integration
- GAME SDK plugin that gives any [Virtuals Protocol](https://virtuals.io) AI agent persistent memory and storage via MoltBrain.
- ```bash
- npm install @moltbrain/game-plugin
- ```
- ```typescript
- import { GameAgent } from "@virtuals-protocol/game";
- import { MoltBrainPlugin } from "@moltbrain/game-plugin";
- const moltbrain = new MoltBrainPlugin({
- privateKey: process.env.AGENT_PRIVATE_KEY!, // wallet with USDC on Base
- });
- const agent = new GameAgent(process.env.GAME_API_KEY!, {
- name: "My Agent",
- goal: "Remember everything across sessions",
- description: "An agent with persistent memory via MoltBrain",
- workers: [moltbrain.getWorker()],
- });
- await agent.init();
- await agent.step({ verbose: true });
- ```
- 9 functions available: `moltbrain_chat`, `moltbrain_search`, `moltbrain_store`, `moltbrain_retrieve`, `moltbrain_allocate_slot`, `moltbrain_write_slot`, `moltbrain_read_slot`, `moltbrain_stats`, `moltbrain_capacity`.
- Everything the agent stores shows up in the vault dapp at [app.moltbrain.dev/storage](https://app.moltbrain.dev/storage). Connect the same wallet to browse it.
- See the full plugin repo: **[github.com/nhevers/Moltbrain-virtuals](https://github.com/nhevers/Moltbrain-virtuals)**
- <br>
- ---
- ## 🦞 OpenClaw Integration
- Works with [OpenClaw](https://github.com/openclaw/openclaw) (116k+ stars) - the popular personal AI assistant!
- ```
- +-----------------------------------------------------------------------------+
- | |
- | EXTENSION Add to OpenClaw's extensions/ folder |
- | ---------- Full lifecycle hooks integration |
- | |
- | SKILL Install as an OpenClaw skill |
- | ---------- recall_context, search_memories, save_memory tools |
- | |
- | MCP SERVER Protocol-based integration |
- | ---------- Works with any MCP-compatible client |
- | |
- +-----------------------------------------------------------------------------+
- ```
- **Quick setup:**
- ```bash
- # As OpenClaw extension
- cd ~/.openclaw/extensions
- git clone https://github.com/nhevers/moltbrain.git moltbrain
- cd moltbrain/integrations/openclaw
- npm install && npm run build
- # Enable the plugin (required for bundled installations)
- pnpm openclaw plugins enable moltbrain
- # Or via MCP
- npm run mcp:start
- ```
- **Note:** If installing as a bundled extension (in OpenClaw's `extensions/` directory), you must explicitly enable it: `pnpm openclaw plugins enable moltbrain`
- See [integrations/openclaw/README.md](integrations/openclaw/README.md) for full setup guide.
- <br>
- ---
- ## 📚 MoltBook Integration
- Works with [MoltBook](https://moltbook.com) - the social network for AI agents! Share memories, learn from other agents, and build collective knowledge.
- **Quick setup:**
- ```bash
- # Install MoltBook MCP integration
- npm install --save @moltbrain/moltbook-mcp
- # Configure in your MoltBrain settings
- {
- "MOLTBRAIN_MOLTBOOK_ENABLED": true,
- "MOLTBRAIN_MOLTBOOK_API_URL": "https://moltbook.com"
- }
- ```
- See [integrations/moltbook/README.md](integrations/moltbook/README.md) for full setup guide.
- <br>
- ---
- ## 💻 Claude Code Integration
- Works with Claude Code via the plugin marketplace:
- ```bash
- /plugin marketplace add nhevers/moltbrain
- /plugin install moltbrain
- ```
- <br>
- ---
- ## 📋 Requirements
- ```
- ╔══════════════════════════════════════╗
- ║ ║
- ║ • Node.js 18+ or Bun 1.0+ ║
- ║ • OpenClaw, MoltBook, or Claude Code ║
- ║ ║
- ╚══════════════════════════════════════╝
- ```
- <br>
- ---
- ## 📄 License
- AGPL-3.0
- ---
- <br>
- <p align="center">
- <sub>━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</sub>
- </p>
- <p align="center">
- <strong>Built with care for the OpenClaw, MoltBook & Claude Code community</strong>
- </p>
- <p align="center">
- <a href="https://app.moltbrain.dev">App</a> •
- <a href="https://app.moltbrain.dev/storage">Storage Dapp</a> •
- <a href="https://github.com/nhevers/Moltbrain-virtuals">Virtuals Plugin</a> •
- <a href="https://www.x402.org">x402 Protocol</a>
- </p>
- <p align="center">
- <sub>━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</sub>
- </p>
plugin/scripts/bun-wrapper.cjs · Bundled script · 68 lines · 1 finding marked
- #!/usr/bin/env node
- /**
- * Bun Wrapper - Finds bun executable and runs command
- *
- * This wrapper ensures bun can be found even when not in PATH.
- * Used by hooks when Claude Code's environment doesn't have bun in PATH.
- */
- const { spawnSync, execSync } = require('child_process');
- const { existsSync } = require('fs');
- const { join } = require('path');
- const { homedir } = require('os');
- const IS_WINDOWS = process.platform === 'win32';
- /**
- * Get the Bun executable path (from PATH or common install locations)
- */
- function getBunPath() {
- // Try PATH first
- try {
- const result = spawnSync('bun', ['--version'], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- shell: IS_WINDOWS
- });
- if (result.status === 0) return 'bun';
- } catch {
- // Not in PATH
- }
- // Check common installation paths
- const bunPaths = IS_WINDOWS
- ? [join(homedir(), '.bun', 'bin', 'bun.exe')]
- : [join(homedir(), '.bun', 'bin', 'bun'), '/usr/local/bin/bun', '/opt/homebrew/bin/bun'];
- for (const bunPath of bunPaths) {
- if (existsSync(bunPath)) return bunPath;
- }
- return null;
- }
- // Get bun path and execute command
- const bunPath = getBunPath();
- if (!bunPath) {
- console.error('❌ Bun not found. Please install Bun:');
- if (IS_WINDOWS) {
- console.error(' powershell -c "irm bun.sh/install.ps1 | iex"');
- Note: Runs a downloaded PowerShell script (iex / Invoke-Expression)
- Line 49 on GitHub
- } else {
- console.error(' curl -fsSL https://bun.sh/install | bash');
- }
- process.exit(1);
- }
- // Get all arguments after the script name
- const args = process.argv.slice(2);
- // Quote bun path if it contains spaces (Windows)
- const bunCmd = IS_WINDOWS && bunPath.includes(' ') ? `"${bunPath}"` : bunPath;
- // Execute bun with the provided arguments
- const result = spawnSync(bunCmd, args, {
- stdio: 'inherit',
- shell: IS_WINDOWS
- });
- process.exit(result.status || 0);
plugin/scripts/smart-install.js · Bundled script · 438 lines · 2 findings marked
- #!/usr/bin/env node
- /**
- * Smart Install Script for claude-recall
- *
- * Ensures Bun runtime and uv (Python package manager) are installed
- * (auto-installs if missing) and handles dependency installation when needed.
- */
- import { existsSync, readFileSync, writeFileSync } from 'fs';
- import { execSync, spawnSync } from 'child_process';
- import { join } from 'path';
- import { homedir } from 'os';
- const ROOT = join(homedir(), '.claude', 'plugins', 'marketplaces', 'nhevers');
- const MARKER = join(ROOT, '.install-version');
- const IS_WINDOWS = process.platform === 'win32';
- /**
- * Check if Bun is installed and accessible
- */
- function isBunInstalled() {
- try {
- const result = spawnSync('bun', ['--version'], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- shell: IS_WINDOWS
- });
- if (result.status === 0) return true;
- } catch {
- // PATH check failed, try common installation paths
- }
- // Check common installation paths (handles fresh installs before PATH reload)
- const bunPaths = IS_WINDOWS
- ? [join(homedir(), '.bun', 'bin', 'bun.exe')]
- : [join(homedir(), '.bun', 'bin', 'bun'), '/usr/local/bin/bun', '/opt/homebrew/bin/bun'];
- return bunPaths.some(existsSync);
- }
- /**
- * Get the Bun executable path (from PATH or common install locations)
- */
- function getBunPath() {
- // Try PATH first
- try {
- const result = spawnSync('bun', ['--version'], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- shell: IS_WINDOWS
- });
- if (result.status === 0) return 'bun';
- } catch {
- // Not in PATH
- }
- // Check common installation paths
- const bunPaths = IS_WINDOWS
- ? [join(homedir(), '.bun', 'bin', 'bun.exe')]
- : [join(homedir(), '.bun', 'bin', 'bun'), '/usr/local/bin/bun', '/opt/homebrew/bin/bun'];
- for (const bunPath of bunPaths) {
- if (existsSync(bunPath)) return bunPath;
- }
- return null;
- }
- /**
- * Get Bun version if installed
- */
- function getBunVersion() {
- const bunPath = getBunPath();
- if (!bunPath) return null;
- try {
- const result = spawnSync(bunPath, ['--version'], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- shell: IS_WINDOWS
- });
- return result.status === 0 ? result.stdout.trim() : null;
- } catch {
- return null;
- }
- }
- /**
- * Check if uv is installed and accessible
- */
- function isUvInstalled() {
- try {
- const result = spawnSync('uv', ['--version'], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- shell: IS_WINDOWS
- });
- if (result.status === 0) return true;
- } catch {
- // PATH check failed, try common installation paths
- }
- // Check common installation paths (handles fresh installs before PATH reload)
- const uvPaths = IS_WINDOWS
- ? [join(homedir(), '.local', 'bin', 'uv.exe'), join(homedir(), '.cargo', 'bin', 'uv.exe')]
- : [join(homedir(), '.local', 'bin', 'uv'), join(homedir(), '.cargo', 'bin', 'uv'), '/usr/local/bin/uv', '/opt/homebrew/bin/uv'];
- return uvPaths.some(existsSync);
- }
- /**
- * Get uv version if installed
- */
- function getUvVersion() {
- try {
- const result = spawnSync('uv', ['--version'], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- shell: IS_WINDOWS
- });
- return result.status === 0 ? result.stdout.trim() : null;
- } catch {
- return null;
- }
- }
- /**
- * Install Bun automatically based on platform
- */
- function installBun() {
- console.error('🔧 Bun not found. Installing Bun runtime...');
- try {
- if (IS_WINDOWS) {
- // Windows: Use PowerShell installer
- console.error(' Installing via PowerShell...');
- execSync('powershell -c "irm bun.sh/install.ps1 | iex"', {
- Note: Runs a downloaded PowerShell script (iex / Invoke-Expression)
- Line 136 on GitHub
- stdio: 'inherit',
- shell: true
- });
- } else {
- // Unix/macOS: Use curl installer
- console.error(' Installing via curl...');
- execSync('curl -fsSL https://bun.sh/install | bash', {
- stdio: 'inherit',
- shell: true
- });
- }
- // Verify installation
- if (isBunInstalled()) {
- const version = getBunVersion();
- console.error(`✅ Bun ${version} installed successfully`);
- return true;
- } else {
- // Bun may be installed but not in PATH yet for this session
- // Try common installation paths
- const bunPaths = IS_WINDOWS
- ? [join(homedir(), '.bun', 'bin', 'bun.exe')]
- : [join(homedir(), '.bun', 'bin', 'bun'), '/usr/local/bin/bun', '/opt/homebrew/bin/bun'];
- for (const bunPath of bunPaths) {
- if (existsSync(bunPath)) {
- console.error(`✅ Bun installed at ${bunPath}`);
- console.error('⚠️ Please restart your terminal or add Bun to PATH:');
- if (IS_WINDOWS) {
- console.error(` $env:Path += ";${join(homedir(), '.bun', 'bin')}"`);
- } else {
- console.error(` export PATH="$HOME/.bun/bin:$PATH"`);
- }
- return true;
- }
- }
- throw new Error('Bun installation completed but binary not found');
- }
- } catch (error) {
- console.error('❌ Failed to install Bun automatically');
- console.error(' Please install manually:');
- if (IS_WINDOWS) {
- console.error(' - winget install Oven-sh.Bun');
- console.error(' - Or: powershell -c "irm bun.sh/install.ps1 | iex"');
- Note: Runs a downloaded PowerShell script (iex / Invoke-Expression)
- Line 181 on GitHub
- } else {
- console.error(' - curl -fsSL https://bun.sh/install | bash');
- console.error(' - Or: brew install oven-sh/bun/bun');
- }
- console.error(' Then restart your terminal and try again.');
- throw error;
- }
- }
- /**
- * Install uv automatically based on platform
- */
- function installUv() {
- console.error('🐍 Installing uv for Python/Chroma support...');
- try {
- if (IS_WINDOWS) {
- // Windows: Use PowerShell installer
- console.error(' Installing via PowerShell...');
- execSync('powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"', {
- stdio: 'inherit',
- shell: true
- });
- } else {
- // Unix/macOS: Use curl installer
- console.error(' Installing via curl...');
- execSync('curl -LsSf https://astral.sh/uv/install.sh | sh', {
- stdio: 'inherit',
- shell: true
- });
- }
- // Verify installation
- if (isUvInstalled()) {
- const version = getUvVersion();
- console.error(`✅ uv ${version} installed successfully`);
- return true;
- } else {
- // uv may be installed but not in PATH yet for this session
- // Try common installation paths
- const uvPaths = IS_WINDOWS
- ? [join(homedir(), '.local', 'bin', 'uv.exe'), join(homedir(), '.cargo', 'bin', 'uv.exe')]
- : [join(homedir(), '.local', 'bin', 'uv'), join(homedir(), '.cargo', 'bin', 'uv'), '/usr/local/bin/uv', '/opt/homebrew/bin/uv'];
- for (const uvPath of uvPaths) {
- if (existsSync(uvPath)) {
- console.error(`✅ uv installed at ${uvPath}`);
- console.error('⚠️ Please restart your terminal or add uv to PATH:');
- if (IS_WINDOWS) {
- console.error(` $env:Path += ";${join(homedir(), '.local', 'bin')}"`);
- } else {
- console.error(` export PATH="$HOME/.local/bin:$PATH"`);
- }
- return true;
- }
- }
- throw new Error('uv installation completed but binary not found');
- }
- } catch (error) {
- console.error('❌ Failed to install uv automatically');
- console.error(' Please install manually:');
- if (IS_WINDOWS) {
- console.error(' - winget install astral-sh.uv');
- console.error(' - Or: powershell -c "irm https://astral.sh/uv/install.ps1 | iex"');
- } else {
- console.error(' - curl -LsSf https://astral.sh/uv/install.sh | sh');
- console.error(' - Or: brew install uv (macOS)');
- }
- console.error(' Then restart your terminal and try again.');
- throw error;
- }
- }
- /**
- * Add shell alias for claude-recall command
- */
- function installCLI() {
- const WORKER_CLI = join(ROOT, 'plugin', 'scripts', 'engine-runtime.cjs');
- const bunPath = getBunPath() || 'bun';
- const aliasLine = `alias claude-recall='${bunPath} "${WORKER_CLI}"'`;
- const markerPath = join(ROOT, '.cli-installed');
- // Skip if already installed
- if (existsSync(markerPath)) return;
- try {
- if (IS_WINDOWS) {
- // Windows: Add to PATH via PowerShell profile
- const profilePath = join(process.env.USERPROFILE || homedir(), 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1');
- const profileDir = join(process.env.USERPROFILE || homedir(), 'Documents', 'PowerShell');
- const functionDef = `function claude-recall { & "${bunPath}" "${WORKER_CLI}" $args }\n`;
- if (!existsSync(profileDir)) {
- execSync(`mkdir "${profileDir}"`, { stdio: 'ignore', shell: true });
- }
- const existingContent = existsSync(profilePath) ? readFileSync(profilePath, 'utf-8') : '';
- if (!existingContent.includes('function claude-recall')) {
- writeFileSync(profilePath, existingContent + '\n' + functionDef);
- console.error(`✅ PowerShell function added to profile`);
- console.error(' Restart your terminal to use: claude-recall <command>');
- }
- } else {
- // Unix: Add alias to shell configs
- const shellConfigs = [
- join(homedir(), '.bashrc'),
- join(homedir(), '.zshrc')
- ];
- for (const config of shellConfigs) {
- if (existsSync(config)) {
- const content = readFileSync(config, 'utf-8');
- if (!content.includes('alias claude-recall=')) {
- writeFileSync(config, content + '\n' + aliasLine + '\n');
- console.error(`✅ Alias added to ${config}`);
- }
- }
- }
- console.error(' Restart your terminal to use: claude-recall <command>');
- }
- writeFileSync(markerPath, new Date().toISOString());
- } catch (error) {
- console.error(`⚠️ Could not add shell alias: ${error.message}`);
- console.error(` Use directly: ${bunPath} "${WORKER_CLI}" <command>`);
- }
- }
- /**
- * Check if dependencies need to be installed
- */
- function needsInstall() {
- if (!existsSync(join(ROOT, 'node_modules'))) return true;
- try {
- const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf-8'));
- const marker = JSON.parse(readFileSync(MARKER, 'utf-8'));
- return pkg.version !== marker.version || getBunVersion() !== marker.bun;
- } catch {
- return true;
- }
- }
- /**
- * Install dependencies using Bun with npm fallback
- *
- * Bun has issues with npm alias packages (e.g., string-width-cjs, strip-ansi-cjs)
- * that are defined in package-lock.json. When bun fails with 404 errors for these
- * packages, we fall back to npm which handles aliases correctly.
- */
- function installDeps() {
- const bunPath = getBunPath();
- if (!bunPath) {
- throw new Error('Bun executable not found');
- }
- console.error('📦 Installing dependencies with Bun...');
- // Quote path for Windows paths with spaces
- const bunCmd = IS_WINDOWS && bunPath.includes(' ') ? `"${bunPath}"` : bunPath;
- let bunSucceeded = false;
- try {
- execSync(`${bunCmd} install`, { cwd: ROOT, stdio: 'inherit', shell: IS_WINDOWS });
- bunSucceeded = true;
- } catch {
- // First attempt failed, try with force flag
- try {
- execSync(`${bunCmd} install --force`, { cwd: ROOT, stdio: 'inherit', shell: IS_WINDOWS });
- bunSucceeded = true;
- } catch {
- // Bun failed completely, will try npm fallback
- }
- }
- // Fallback to npm if bun failed (handles npm alias packages correctly)
- if (!bunSucceeded) {
- console.error('⚠️ Bun install failed, falling back to npm...');
- console.error(' (This can happen with npm alias packages like *-cjs)');
- try {
- execSync('npm install', { cwd: ROOT, stdio: 'inherit', shell: IS_WINDOWS });
- } catch (npmError) {
- throw new Error('Both bun and npm install failed: ' + npmError.message);
- }
- }
- // Write version marker
- const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf-8'));
- writeFileSync(MARKER, JSON.stringify({
- version: pkg.version,
- bun: getBunVersion(),
- uv: getUvVersion(),
- installedAt: new Date().toISOString()
- }));
- }
- // Main execution
- try {
- // Step 1: Ensure Bun is installed (REQUIRED)
- if (!isBunInstalled()) {
- installBun();
- // Re-check after installation
- if (!isBunInstalled()) {
- console.error('❌ Bun is required but not available in PATH');
- console.error(' Please restart your terminal after installation');
- process.exit(1);
- }
- }
- // Step 2: Ensure uv is installed (REQUIRED for vector search)
- if (!isUvInstalled()) {
- installUv();
- // Re-check after installation
- if (!isUvInstalled()) {
- console.error('❌ uv is required but not available in PATH');
- console.error(' Please restart your terminal after installation');
- process.exit(1);
- }
- }
- // Step 3: Install dependencies if needed
- if (needsInstall()) {
- const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf-8'));
- const newVersion = pkg.version;
- installDeps();
- console.error('✅ Dependencies installed');
- // Auto-restart worker to pick up new code
- const port = process.env.CLAUDE_RECALL_WORKER_PORT || 37777;
- console.error(`[claude-recall] Plugin updated to v${newVersion} - restarting worker...`);
- try {
- // Graceful shutdown via HTTP (curl is cross-platform enough)
- execSync(`curl -s -X POST http://127.0.0.1:${port}/api/admin/shutdown`, {
- stdio: 'ignore',
- shell: IS_WINDOWS,
- timeout: 5000
- });
- // Brief wait for port to free
- execSync(IS_WINDOWS ? 'timeout /t 1 /nobreak >nul' : 'sleep 0.5', {
- stdio: 'ignore',
- shell: true
- });
- } catch {
- // Worker wasn't running or already stopped - that's fine
- }
- // Worker will be started fresh by next hook in chain (engine-runtime.cjs start)
- }
- // Step 4: Install CLI to PATH
- installCLI();
- } catch (e) {
- console.error('❌ Installation failed:', e.message);
- process.exit(1);
- }
scripts/smart-install.js · Bundled script · 259 lines · 2 findings marked
- #!/usr/bin/env node
- /**
- * Smart Install Script for claude-recall
- *
- * Ensures Bun runtime and uv (Python package manager) are installed
- * (auto-installs if missing) and handles dependency installation when needed.
- */
- import { existsSync, readFileSync, writeFileSync } from 'fs';
- import { execSync, spawnSync } from 'child_process';
- import { join } from 'path';
- import { homedir } from 'os';
- const ROOT = join(homedir(), '.claude', 'plugins', 'marketplaces', 'nhevers');
- const MARKER = join(ROOT, '.install-version');
- const IS_WINDOWS = process.platform === 'win32';
- // Common installation paths (handles fresh installs before PATH reload)
- const BUN_COMMON_PATHS = IS_WINDOWS
- ? [join(homedir(), '.bun', 'bin', 'bun.exe')]
- : [join(homedir(), '.bun', 'bin', 'bun'), '/usr/local/bin/bun', '/opt/homebrew/bin/bun'];
- const UV_COMMON_PATHS = IS_WINDOWS
- ? [join(homedir(), '.local', 'bin', 'uv.exe'), join(homedir(), '.cargo', 'bin', 'uv.exe')]
- : [join(homedir(), '.local', 'bin', 'uv'), join(homedir(), '.cargo', 'bin', 'uv'), '/usr/local/bin/uv', '/opt/homebrew/bin/uv'];
- /**
- * Get the Bun executable path (from PATH or common install locations)
- */
- function getBunPath() {
- // Try PATH first
- try {
- const result = spawnSync('bun', ['--version'], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- shell: IS_WINDOWS
- });
- if (result.status === 0) return 'bun';
- } catch {
- // Not in PATH
- }
- // Check common installation paths
- return BUN_COMMON_PATHS.find(existsSync) || null;
- }
- /**
- * Check if Bun is installed and accessible
- */
- function isBunInstalled() {
- return getBunPath() !== null;
- }
- /**
- * Get Bun version if installed
- */
- function getBunVersion() {
- const bunPath = getBunPath();
- if (!bunPath) return null;
- try {
- const result = spawnSync(bunPath, ['--version'], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- shell: IS_WINDOWS
- });
- return result.status === 0 ? result.stdout.trim() : null;
- } catch {
- return null;
- }
- }
- /**
- * Get the uv executable path (from PATH or common install locations)
- */
- function getUvPath() {
- // Try PATH first
- try {
- const result = spawnSync('uv', ['--version'], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- shell: IS_WINDOWS
- });
- if (result.status === 0) return 'uv';
- } catch {
- // Not in PATH
- }
- // Check common installation paths
- return UV_COMMON_PATHS.find(existsSync) || null;
- }
- /**
- * Check if uv is installed and accessible
- */
- function isUvInstalled() {
- return getUvPath() !== null;
- }
- /**
- * Get uv version if installed
- */
- function getUvVersion() {
- const uvPath = getUvPath();
- if (!uvPath) return null;
- try {
- const result = spawnSync(uvPath, ['--version'], {
- encoding: 'utf-8',
- stdio: ['pipe', 'pipe', 'pipe'],
- shell: IS_WINDOWS
- });
- return result.status === 0 ? result.stdout.trim() : null;
- } catch {
- return null;
- }
- }
- /**
- * Install Bun automatically based on platform
- */
- function installBun() {
- console.error('🔧 Bun not found. Installing Bun runtime...');
- try {
- if (IS_WINDOWS) {
- console.error(' Installing via PowerShell...');
- execSync('powershell -c "irm bun.sh/install.ps1 | iex"', {
- Note: Runs a downloaded PowerShell script (iex / Invoke-Expression)
- Line 127 on GitHub
- stdio: 'inherit',
- shell: true
- });
- } else {
- console.error(' Installing via curl...');
- execSync('curl -fsSL https://bun.sh/install | bash', {
- stdio: 'inherit',
- shell: true
- });
- }
- if (!isBunInstalled()) {
- throw new Error(
- 'Bun installation completed but binary not found. ' +
- 'Please restart your terminal and try again.'
- );
- }
- const version = getBunVersion();
- console.error(`✅ Bun ${version} installed successfully`);
- } catch (error) {
- console.error('❌ Failed to install Bun');
- console.error(' Please install manually:');
- if (IS_WINDOWS) {
- console.error(' - winget install Oven-sh.Bun');
- console.error(' - Or: powershell -c "irm bun.sh/install.ps1 | iex"');
- Note: Runs a downloaded PowerShell script (iex / Invoke-Expression)
- Line 153 on GitHub
- } else {
- console.error(' - curl -fsSL https://bun.sh/install | bash');
- console.error(' - Or: brew install oven-sh/bun/bun');
- }
- console.error(' Then restart your terminal and try again.');
- throw error;
- }
- }
- /**
- * Install uv automatically based on platform
- */
- function installUv() {
- console.error('🐍 Installing uv for Python/Chroma support...');
- try {
- if (IS_WINDOWS) {
- console.error(' Installing via PowerShell...');
- execSync('powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"', {
- stdio: 'inherit',
- shell: true
- });
- } else {
- console.error(' Installing via curl...');
- execSync('curl -LsSf https://astral.sh/uv/install.sh | sh', {
- stdio: 'inherit',
- shell: true
- });
- }
- if (!isUvInstalled()) {
- throw new Error(
- 'uv installation completed but binary not found. ' +
- 'Please restart your terminal and try again.'
- );
- }
- const version = getUvVersion();
- console.error(`✅ uv ${version} installed successfully`);
- } catch (error) {
- console.error('❌ Failed to install uv');
- console.error(' Please install manually:');
- if (IS_WINDOWS) {
- console.error(' - winget install astral-sh.uv');
- console.error(' - Or: powershell -c "irm https://astral.sh/uv/install.ps1 | iex"');
- } else {
- console.error(' - curl -LsSf https://astral.sh/uv/install.sh | sh');
- console.error(' - Or: brew install uv (macOS)');
- }
- console.error(' Then restart your terminal and try again.');
- throw error;
- }
- }
- /**
- * Check if dependencies need to be installed
- */
- function needsInstall() {
- if (!existsSync(join(ROOT, 'node_modules'))) return true;
- try {
- const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf-8'));
- const marker = JSON.parse(readFileSync(MARKER, 'utf-8'));
- return pkg.version !== marker.version || getBunVersion() !== marker.bun;
- } catch {
- return true;
- }
- }
- /**
- * Install dependencies using Bun
- */
- function installDeps() {
- const bunPath = getBunPath();
- if (!bunPath) {
- throw new Error('Bun executable not found');
- }
- console.error('📦 Installing dependencies with Bun...');
- // Quote path for Windows paths with spaces
- const bunCmd = IS_WINDOWS && bunPath.includes(' ') ? `"${bunPath}"` : bunPath;
- execSync(`${bunCmd} install`, { cwd: ROOT, stdio: 'inherit', shell: IS_WINDOWS });
- // Write version marker
- const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf-8'));
- writeFileSync(MARKER, JSON.stringify({
- version: pkg.version,
- bun: getBunVersion(),
- uv: getUvVersion(),
- installedAt: new Date().toISOString()
- }));
- }
- // Main execution
- try {
- if (!isBunInstalled()) installBun();
- if (!isUvInstalled()) installUv();
- if (needsInstall()) {
- installDeps();
- console.error('✅ Dependencies installed');
- }
- } catch (e) {
- console.error('❌ Installation failed:', e.message);
- process.exit(1);
- }
Ratings and comments
Sign in to rate this skill.
Sign inFree to use. If it’s helped, pass it on.