brainjar

module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: MIT

README

brainjar

Shape how your AI thinks.

brainjar composes soul + persona + rules + procedure into prompts for AI agents and emits skills as on-demand capabilities to the platform's skills directory. It's a Go CLI that runs offline against a single local SQLite workspace. No server, no network calls, no account.

Status: pre-1.0. CLI local mode, Claude platform sync (Codex and Cursor sync without skill emit), HTTP API, MCP tool surface, five content primitives, brain bundles. Single-workspace, single-user.

Install

There are no binary releases yet. Build from source:

git clone https://github.com/brainjar-sh/brainjar
cd brainjar
go build -o brainjar ./cmd/brainjar

Or with the included just recipes:

just build   # go build -o brainjar ./cmd/brainjar
just test    # go test ./...
just lint    # golangci-lint run ./...

Requires Go 1.25 or later. Put the resulting brainjar binary on your PATH.

Quick start

brainjar init                                             # create ~/.brainjar; prints one API key — save it
echo "You speak with conviction"          | brainjar soul create straight-shooter
echo "You are the CTO"                    | brainjar persona create cto
echo "Test before merging"                | brainjar rule create testing
echo "1. Design  2. Approve  3. Build"    | brainjar procedure create delivery
brainjar soul use straight-shooter
brainjar persona use cto
brainjar rule add testing
brainjar procedure use delivery
brainjar compose > prompt.txt                             # compose effective state

Content for soul create, persona create, rule create, and procedure create comes from stdin, --content "...", or --file <path> in that precedence.

Save the current soul+persona+rules+procedure (and optional skills) as a reusable brain:

brainjar brain save cto \
  --soul straight-shooter --persona cto --procedure delivery \
  --rule testing \
  --skill incident-response                             # repeatable; or --skills a,b,c
brainjar brain save cto \
  --soul straight-shooter --persona cto \
  --platform claude --model opus                        # pin platform + default model
brainjar compose cto > prompt.txt                       # compose from a brain
brainjar compose --persona architect --task "design the auth layer"

Activate a saved brain on the workspace state in one shot:

brainjar brain use cto                                  # load soul + persona + procedure + rules + skills
brainjar sync                                           # write the composed prompt + emit skill files

Inspect what's active:

brainjar status

Primitives

brainjar splits agent configuration into five content kinds. Four of them compose into the prompt; the fifth (skills) is on-demand and emitted to the platform's skills directory rather than inlined.

Primitive Answers Cardinality Composed order
soul Who are you, in voice and character? 1 per state/brain 1st
persona What role are you playing right now? 1 per state/brain 2nd
rule What constraints apply, regardless of role? N 3rd
procedure How do you carry out the work, step by step? 0 or 1 4th
skill What capability should load on demand for matching tasks? N not composed — emitted to disk

A brain is a saved bundle of (soul, persona, rules, optional procedure, skills) you can name and re-activate. State is the live, mutable version of the same shape — what brainjar sync writes to your platform.

Skills

A skill is a Markdown body the platform's runtime loads when the user's task matches its description or triggers. brainjar stores skills in the workspace and writes one <slug>/SKILL.md per resolved skill on brainjar sync. Each skill carries a scopeproject skills land under <repo>/.claude/skills/, user skills under ~/.claude/skills/. brainjar drops a .brainjar-managed marker into each emitted directory so prune only removes brainjar-owned skills and leaves hand-authored ones alone.

Skills do not enter the composed prompt — they appear on compose --json as skills reference metadata so callers know what's available, but bodies stay on disk. Today only Claude Code consumes the emitted SKILL files; Codex and Cursor sync warns that skills are unsupported and continues.

Commands

Command Purpose
brainjar init [--force] Create the home directory, run migrations, write config.yaml. Prints a banner and a structured progress report.
brainjar guide list|show Browse the operational guides shipped in the binary as Claude Code SKILL.md files.
brainjar reset [--yes] Remove brainjar.db and config.yaml from the home.
brainjar soul create|list|show|delete|use|drop Manage souls — the top-level voice.
brainjar persona create|list|show|delete|use|drop Manage personas — the role adopted.
brainjar rule create|list|show|delete|add|remove Manage rules — composable guidance fragments.
brainjar procedure create|list|show|delete|use|drop Manage procedures — step-by-step playbooks.
brainjar skill create|list|show|delete|use|drop|attach|detach|emit Manage skills — on-demand SKILL.md files. use/drop toggle the workspace overlay; attach/detach bind to a brain; emit force-rewrites the platform skill files.
brainjar brain save|list|show|delete|use Named bundles of soul + persona + rules + procedure + skills; use loads one wholesale into state.
brainjar compose [brain] [--persona slug] [--task "..."] Compose a prompt to stdout.
brainjar status Show the effective state and layer chain (including resolved skills).
brainjar versions <type> <slug> [<n>] List or print archived versions of a soul, persona, rule, procedure, or skill.
brainjar pack export|import Export or import the workspace as a JSON bundle (includes skills).
brainjar sync [--platform claude] Write the composed prompt and emit resolved skills to the platform.
brainjar platform list|models Inspect registered platform adapters; models [<platform>] lists a platform's model catalog.
brainjar shell [--brain|--persona] [--rules] [-- AGENT_ARGS...] Spawn an agent (claude, codex) with a composed prompt for this session only — nothing written to disk, --json not supported. Cursor has no CLI injection surface.
brainjar hooks install|remove|status Register platform hooks so the synced config stays current.
brainjar workspace create|list|switch|rename|delete Manage workspaces — isolation boundaries for content.
brainjar api-key create|list|revoke Mint and revoke API keys for the active workspace.
brainjar serve [--host] [--port] Start the HTTP API server (JSON over HTTP + MCP at /mcp).
brainjar mcp Run as an MCP server over stdio (for agent registration).
brainjar completion bash|zsh|fish|powershell Emit a shell-completion script for brainjar.
brainjar man [dir] Generate man pages (default ./man).

Run brainjar <cmd> --help for flags and examples on any command.

Global flags

Flag Description
--home <dir> Override the brainjar home directory.
--json Emit machine-readable JSON on stdout; errors go to stderr as a structured envelope.
-h, --help Command help.
-v, --version Print the binary version.
Home resolution

The home directory is resolved in this order:

  1. --home <dir> flag
  2. $BRAINJAR_HOME environment variable
  3. ~/.brainjar

It holds config.yaml and brainjar.db (SQLite). Nothing else is written there by brainjar itself.

Agent mode (--json)

Every command supports --json. In JSON mode:

  • Success output on stdout is a single JSON document.

  • Errors on stderr are a structured envelope:

    {
      "error": {
        "code": "BAD_REQUEST",
        "message": "invalid references",
        "hint": "re-run `brainjar init --force` after backing up",
        "invalid_refs": { "soul_slug": "ghost", "rule_slugs": ["missing"] }
      }
    }
    

    code is one of NOT_FOUND, CONFLICT, BAD_REQUEST, UNAUTHORIZED, FORBIDDEN, INTERNAL. hint and invalid_refs are optional.

  • Human warnings (missing slugs during compose, etc.) still go to stderr so they don't pollute a piped prompt.

Server and MCP

brainjar exposes the same content through two surfaces: CLI and MCP. Both share one SQLite workspace.

HTTP server
brainjar serve --port 8080

The server listens at http://127.0.0.1:8080 and exposes one application endpoint — MCP Streamable HTTP at /mcp. Every request needs Authorization: Bearer <key>, where <key> is the plaintext printed once by brainjar init (or by brainjar api-key create for additional keys). The server only stores the SHA-256 hash — lose the plaintext and you revoke and re-mint. /healthz (liveness) and /readyz (DB-reachable readiness) are unauthenticated and intended for container probes.

MCP over stdio

brainjar mcp runs an MCP server on stdio, bound to the same workspace the CLI uses. Register it with your agent the way that agent registers any stdio MCP server. For Claude Code:

claude mcp add brainjar -- brainjar mcp
# or, if you use a non-default workspace:
claude mcp add brainjar -- brainjar --home ~/.brainjar-prod mcp

From that point on, tools like soul_list, persona_save, skill_save, compose, and status show up as MCP tools in your Claude session. The skill surface is skill_list / show / save / delete / attach / detach; brain_save accepts skill_slugs alongside its rule and procedure references.

Shell completions

brainjar completion <shell> prints a completion script for bash, zsh, fish, or powershell. Pipe the output into your shell's completion directory:

# bash (system-wide)
brainjar completion bash | sudo tee /etc/bash_completion.d/brainjar > /dev/null

# zsh (first fpath entry; reload with `exec zsh`)
brainjar completion zsh > "${fpath[1]}/_brainjar"

# fish
brainjar completion fish > ~/.config/fish/completions/brainjar.fish

# PowerShell (dot-source the file in $PROFILE)
brainjar completion powershell > brainjar.ps1

Man pages

brainjar man [dir] writes nroff(1) man pages for every subcommand into dir (default ./man). Packagers typically install them under $prefix/share/man/man1/:

brainjar man /usr/local/share/man/man1
man brainjar-shell

Exit codes

Exit codes are a stable contract — safe for scripts and CI:

Code Meaning
0 Success
1 Generic error
2 Bad usage or validation failure
3 Not found
4 Conflict (duplicate slug, etc.)
5 Reserved for auth (unused in local mode)

License

MIT — see LICENSE.

Directories

Path Synopsis
cmd
brainjar command
Package main is the entry point for the brainjar CLI.
Package main is the entry point for the brainjar CLI.
database
gen
internal
backend
Package backend wires the app layer to a concrete store.
Package backend wires the app layer to a concrete store.
bundle
Package bundle defines the content-bundle serialization format used by pack export/import (file-based CLI) and admin export/import (HTTP).
Package bundle defines the content-bundle serialization format used by pack export/import (file-based CLI) and admin export/import (HTTP).
cli
Package cli implements the brainjar command-line interface on top of cobra.
Package cli implements the brainjar command-line interface on top of cobra.
guides
Package guides ships brainjar-authored markdown content as Claude Code SKILL.md files.
Package guides ships brainjar-authored markdown content as Claude Code SKILL.md files.
http/server
Package server implements the brainjar HTTP server.
Package server implements the brainjar HTTP server.
mcp/server
Package server builds the brainjar MCP server.
Package server builds the brainjar MCP server.
mcp/tools
Package tools holds the brainjar MCP tool implementations.
Package tools holds the brainjar MCP tool implementations.
platform
Package platform adapts brainjar's composed prompts to agent-specific config files on disk.
Package platform adapts brainjar's composed prompts to agent-specific config files on disk.
platform/adapterkit
Package adapterkit holds the helpers shared by every brainjar Platform adapter: marker constants, brainjar brand strings, atomic file / JSON I/O, hook-entry identity, and the managed-section merge algorithm.
Package adapterkit holds the helpers shared by every brainjar Platform adapter: marker constants, brainjar brand strings, atomic file / JSON I/O, hook-entry identity, and the managed-section merge algorithm.
platform/claude
Package claude is the brainjar Platform adapter for Claude Code.
Package claude is the brainjar Platform adapter for Claude Code.
platform/codex
Package codex is the brainjar Platform adapter for OpenAI Codex CLI.
Package codex is the brainjar Platform adapter for OpenAI Codex CLI.
platform/cursor
Package cursor is the brainjar Platform adapter for the Cursor IDE (cursor.com).
Package cursor is the brainjar Platform adapter for the Cursor IDE (cursor.com).
platform/skillemit
Package skillemit owns the per-scope skill writer + pruner shared between the embedded guides emit step and every platform adapter that knows how to land workspace skills on disk (Claude today, more later).
Package skillemit owns the per-scope skill writer + pruner shared between the embedded guides emit step and every platform adapter that knows how to land workspace skills on disk (Claude today, more later).
platform/testutil
Package testutil provides shared test contracts that every platform adapter runs against.
Package testutil provides shared test contracts that every platform adapter runs against.
secrets
Package secrets resolves an api_key_ref (e.g.
Package secrets resolves an api_key_ref (e.g.
updater
Package updater implements `brainjar upgrade` — in-process self-update that fetches the latest release from R2, verifies the cosign bundle against a pinned identity, and atomically swaps the running binary.
Package updater implements `brainjar upgrade` — in-process self-update that fetches the latest release from R2, verifies the cosign bundle against a pinned identity, and atomically swaps the running binary.
pkg
errors
Package errors is brainjar's single domain-error type.
Package errors is brainjar's single domain-error type.
version
Package version holds the brainjar binary version as a single source of truth.
Package version holds the brainjar binary version as a single source of truth.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL