← Back to Skills Marketplace
p0lish

brainmd

by p0lish · GitHub ↗ · v0.1.3 · MIT-0
cross-platform ⚠ suspicious
374
Downloads
0
Stars
1
Active Installs
4
Versions
Install in OpenClaw
/install brainmd
Description
Neuroplastic self-modifying runtime for AI agents. Creates a file-based 'brain' that learns from interactions: reflexes (fast-path responses), habits (learne...
README (SKILL.md)

brainmd

File-based nervous system for AI agents. Behaviors that work get stronger. Behaviors that fail get weaker. Unused patterns decay. Mistakes leave scars.


What It Is

brainmd gives your agent a persistent behavioral memory that survives session restarts. It's not a knowledge base — it's muscle memory. It tracks how the agent behaves, not what it knows.

Three layers complement each other:

Layer File Purpose
brainmd brain/weights/pathways.json Behavioral reinforcement — what works, what doesn't
Long-term memory MEMORY.md Semantic facts — decisions, people, context
Daily log memory/YYYY-MM-DD.md Episodic notes — what happened today

brainmd is the only layer that self-modifies. The others are written by the agent, not evolved by it.


Installation

clawhub install brainmd

Then initialize the brain in your workspace:

cd ~/.openclaw/workspace
./skills/brainmd/scripts/init-brain.sh brain/

This creates:

brain/
├── reflexes/           # Fast-path decision scripts
├── habits/
│   └── preferences.json
├── weights/
│   └── pathways.json   # ← the core state file
├── cortex/
│   └── review.js       # ← the self-review engine
└── mutations/          # Immutable audit log

Wiring Into OpenClaw

Step 1 — AGENTS.md

Add a startup check so the agent reads its neural state at session start:

## 🧠 brainmd — Consult Your Brain

After reading memory files, check your neural state:

```bash
node ~/.openclaw/workspace/brain/cortex/review.js status

Before acting on anything non-trivial, scan for relevant pathways:

  • Weak pathways (\x3C 0.5) = you've failed here before. Be careful, double-check.
  • Strong pathways (> 0.8) = proven patterns. Trust them, act fast.
  • Dying pathways (decaying) = you're forgetting something. Re-evaluate.

After notable outcomes, record them:

node brain/cortex/review.js record "pathway-name" true/false "what happened"

### Step 2 — HEARTBEAT.md

Wire the review cycle into your heartbeat so it runs automatically:

```markdown
## 🧠 brainmd Self-Check (every heartbeat)

```bash
node ~/.openclaw/workspace/brain/cortex/review.js review
node ~/.openclaw/workspace/brain/cortex/review.js status

On each heartbeat, ask yourself:

  1. Did I make a mistake since last check? → record \x3Cpathway> false "what happened"
  2. Did something work well? → record \x3Cpathway> true "what worked"
  3. Did a new pattern emerge? → let neurogenesis create it

### Step 3 — Seed Initial Pathways

Don't hypothesize — seed from real behavior. Run a few sessions first, then record what you observed:

```bash
node brain/cortex/review.js record "reflex:morning-briefing" true "Supplement reminders sent, user confirmed"
node brain/cortex/review.js record "habit:check-files-before-search" true "Read apartment-search.md before googling apartments"
node brain/cortex/review.js record "reflex:safe-file-deletion" false "Used xargs rm with bad grep, deleted workspace files"

Start with 5–10 pathways. Let the system grow from there.


Daily Usage

Check neural state

node brain/cortex/review.js status

Output shows all pathways with visual weight bars, success rate, fire count, and last outcome. Use this to calibrate confidence before non-trivial actions.

Record an outcome

# Something worked
node brain/cortex/review.js record "habit:remote-service-recovery" true "Fixed broken systemd service, used journalctl to diagnose"

# Something failed
node brain/cortex/review.js record "habit:bulk-subagent-spawning" false "Rate limited all 3 models by spawning 2 Opus agents simultaneously"

New pathways are auto-created at weight 0.30 (neurogenesis). Existing pathways update their stats.

Run the review cycle

node brain/cortex/review.js review

The cortex examines all pathways and applies reinforcement rules:

  • Strengthen (+0.05): ≥3 fires, ≥80% success rate
  • Weaken (−0.10): ≥3 fires, \x3C50% success rate
  • Decay (−0.02): unused for 7+ days
  • Prune: weight hits 0 (pathway removed)

All changes are logged to mutations/ with timestamp and reason.


Pathway Naming Conventions

reflex:timing          # Automatic, fast-path behaviors
habit:check-files      # Learned patterns from repeated interaction
skill:osint-workflow   # Acquired capabilities
instinct:safe-delete   # Safety behaviors (start at high weight, floor at 0.8)

Reading pathway weights

Weight Meaning How to use
0.8–1.0 Proven, trusted Act confidently, don't second-guess
0.5–0.8 Developing Use but verify
0.3–0.5 Weak / new Proceed carefully, double-check
\x3C 0.3 Failing / dying Investigate before using; may need rethinking

Tuning the Learning Rate

Edit thresholds in brain/cortex/review.js:

// Strengthen when success rate >= this
const STRENGTHEN_THRESHOLD = 0.8;

// Weaken when success rate \x3C this
const WEAKEN_THRESHOLD = 0.5;

// Days of inactivity before decay starts
const DECAY_ONSET_DAYS = 7;

// Weight change per review cycle
const DECAY_RATE = 0.02;
const STRENGTHEN_DELTA = 0.05;
const WEAKEN_DELTA = 0.10;

Floor weights (prevent over-pruning)

instinct:* pathways should have a minimum weight floor so they can't be trained away:

{
  "id": "instinct:safe-file-deletion",
  "weight": 0.85,
  "floor": 0.80,
  "fires": 1,
  "successes": 0
}

Add a floor field to pathways in pathways.json to protect them from decay.


Architecture Notes

pathways.json — the core state

{
  "version": 42,
  "pathways": {
    "habit:check-files-before-search": {
      "weight": 0.95,
      "fires": 13,
      "successes": 11,
      "lastFired": "2026-03-25T18:00:00.000Z",
      "lastOutcome": "Read AESTHETIC.md before recommending clothes. Saved a web search.",
      "created": "2025-11-01T00:00:00.000Z"
    }
  }
}

mutations/ — the audit log

Every self-modification writes a timestamped JSON file. Never delete these. They're how you trace why the agent's behavior changed over time.

{
  "type": "strengthen",
  "target": "habit:check-files-before-search",
  "from": 0.90,
  "to": 0.95,
  "reason": "11/13 success rate",
  "timestamp": "2026-03-26T07:00:00.000Z"
}

Integration With Auto-Dream

If you're using scripts/dream.js for memory consolidation, the two systems complement each other:

  • brainmd answers: how should I behave?
  • dream.js answers: what do I know?

Neither replaces the other. Wire both into HEARTBEAT.md for full coverage.


Bootstrapping Checklist

  • Run init-brain.sh to create directory structure
  • Add brainmd status check to AGENTS.md startup routine
  • Add heartbeat entry to HEARTBEAT.md
  • Seed 5–10 pathways from real observed behavior (not theory)
  • Run one manual review to verify reinforcement logic works
  • Check mutations/ after first review to confirm logging
  • Set floor weights on any instinct:* pathways

Design Principles

  1. Everything is mutable — no file is sacred except the mutation log
  2. Use strengthens, disuse weakens — pathways that fire together wire together
  3. Outcomes matter — track what worked, what didn't; guesses don't count
  4. Failures leave scars — the most valuable pathways come from mistakes
  5. Seed from reality — observe first, codify second
  6. Small and composable — one pathway per behavior pattern
  7. The schedule forces honesty — if it's not in HEARTBEAT.md, you'll skip it
Usage Guidance
This skill is doing what it says: a file-based, self-modifying behavioral memory that writes pathway files and logs mutations. The main risks are operational, not covert: it runs Node.js scripts and can create/execute new JS files in the brain/ (and a skills/ directory). Before installing, do the following: - Ensure Node.js is installed (the skill assumes 'node' but metadata didn't declare it). - Install and initialize the brain in a restricted directory (not your entire home or system paths). - Review and lock down permissions on the brain/ folder (prevent world-write, consider a container or isolated workspace). - Avoid granting automated, high-privilege agent processes permission to execute newly created scripts; prefer manual review of generated code or run review.js only, not arbitrary generated scripts. - If you wire this into heartbeat/task callbacks, log every invocation and audit mutations/created scripts regularly. If you want me to, I can produce a short checklist or a hardened init-brain.sh that creates a sandboxed environment and warns on newly created executable scripts.
Capability Analysis
Type: OpenClaw Skill Name: brainmd Version: 0.1.3 The brainmd skill provides a framework for AI agents to implement behavioral reinforcement learning through local file-based state management. It uses a Node.js script (cortex-review.js) to track 'pathway' weights in a JSON file, allowing the agent to 'learn' from successful or failed interactions. The skill includes an initialization script (init-brain.sh) and clear instructions in SKILL.md for the agent to record outcomes and perform self-reviews. While the system describes itself as 'self-modifying,' this refers to the automated updating of its own configuration and audit logs (mutations/) rather than malicious code alteration. No indicators of data exfiltration, unauthorized network access, or harmful prompt injection were found.
Capability Assessment
Purpose & Capability
The name/description, README, SKILL.md and code are aligned: the skill implements a file-based reinforcement system and a cortex engine that updates pathway weights. However the package metadata lists no required binaries while all runtime instructions and scripts require Node.js (the JS files are invoked with node). Also SKILL.md references 'clawhub install' even though there's no install spec — minor mismatches that should be corrected but do not imply malicious intent.
Instruction Scope
Instructions direct the agent to run CLI commands that read and write files under a brain/ workspace (pathways.json, mutations/). That is coherent with the stated goal. The important concern: the system is explicitly self-modifying and allows creation/evolution of scripts (skills/ and reflexes/ directories). If the agent is granted permission to run those generated scripts automatically, it can execute arbitrary JS code created during operation. The SKILL.md also encourages wiring review into automated heartbeats and task callbacks, which increases runtime automation of these modifications.
Install Mechanism
There is no network install spec or external downloads; files are included in the skill bundle and init-brain.sh copies them into the user's workspace. This is low install risk. The only minor incoherence is the SKILL.md's 'clawhub install brainmd' mention without an actual install spec in the package metadata; otherwise no high-risk installers or external URLs are used.
Credentials
The skill requests no credentials or special env vars. It does read and write filesystem state within the brain/ directory. It honors an optional BRAIN_ROOT env var. This is proportionate to a file-based learning system. Be aware SKILL.md encourages reading other agent memory files and injecting pathways into prompts — that implies the agent will read additional workspace files if you wire it that way.
Persistence & Privilege
The skill persists state (weights, mutations) and is explicitly self-modifying. It does not request 'always: true' and does not modify other skills' configs, which is good. The concern is that it creates and can execute scripts inside the brain/ (and a skills/ directory) — combined with automated heartbeats or task callbacks this gives the agent dynamic capability to create and run new code, increasing the blast radius if the agent is allowed to run autonomously. Consider limiting execution privileges and placement to a sandboxed workspace.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install brainmd
  3. After installation, invoke the skill by name or use /brainmd
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v0.1.3
Rewrote SKILL.md with concrete OpenClaw wiring instructions, pathway weight guide, dream.js integration, bootstrapping checklist
v0.1.2
Expanded README with framework-agnostic integration examples
v0.1.1
Fix publish
v0.1.0
Initial release — neuroplastic self-modifying runtime for AI agents
Metadata
Slug brainmd
Version 0.1.3
License MIT-0
All-time Installs 1
Active Installs 1
Total Versions 4
Frequently Asked Questions

What is brainmd?

Neuroplastic self-modifying runtime for AI agents. Creates a file-based 'brain' that learns from interactions: reflexes (fast-path responses), habits (learne... It is an AI Agent Skill for Claude Code / OpenClaw, with 374 downloads so far.

How do I install brainmd?

Run "/install brainmd" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is brainmd free?

Yes, brainmd is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does brainmd support?

brainmd is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created brainmd?

It is built and maintained by p0lish (@p0lish); the current version is v0.1.3.

💬 Comments