JSPM

  • Created
  • Published
  • Downloads 245
  • Score
    100M100P100Q120890F
  • License MIT

Universal AI memory core — generate AI context files from architecture profiles with RAG support

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@shahmilsaari/memory-core) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    memory-core

    Every AI coding agent in your project, following your rules. Automatically.

    You decide the architecture. memory-core remembers it. Every AI tool — Copilot, Cursor, Claude Code, Windsurf, and 10 more — reads those rules before writing a single line of code.

    npx @shahmilsaari/memory-core init

    Fully local or cloud — your choice. v0.2.10


    What does it actually do?

    Without memory-core, every AI agent starts fresh. It doesn't know you're using Clean Architecture. It doesn't know controllers shouldn't call the database. It doesn't know why you made that decision six months ago.

    With memory-core:

    1. You run init once — it verifies your PostgreSQL and Ollama connections, picks your model, lets you choose which agents to generate files for, and installs a pre-commit hook
    2. Those agents read the files and follow your rules — automatically
    3. Watch mode catches violations as you type, not just at commit time
    4. When you commit, the hook checks your code before the commit goes through (advisory by default — logs violations but never blocks)

    Before you start

    You need three things installed:

    What Why Install
    PostgreSQL 14+ Stores your rules and decisions See below
    pgvector Makes search smart (finds similar rules, not just exact matches) See below
    Ollama Runs AI locally — no API key needed See below

    Install

    PostgreSQL

    macOS

    brew install postgresql@16
    brew services start postgresql@16

    Linux

    sudo apt install postgresql postgresql-contrib
    sudo systemctl start postgresql

    Windowsdownload from postgresql.org


    pgvector

    pgvector adds AI-powered search to PostgreSQL.

    macOS + PostgreSQL 17+ (easiest)

    brew install pgvector

    macOS + PostgreSQL 16 (brew's pgvector targets 17+, so build from source)

    xcode-select --install
    git clone --branch v0.8.0 https://github.com/pgvector/pgvector.git /tmp/pgvector
    cd /tmp/pgvector
    make PG_CONFIG=/opt/homebrew/opt/postgresql@16/bin/pg_config
    make install PG_CONFIG=/opt/homebrew/opt/postgresql@16/bin/pg_config

    Linux

    sudo apt install postgresql-16-pgvector   # replace 16 with your version

    Check it worked:

    psql -U $(whoami) -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';"

    Ollama

    Ollama runs AI models on your machine. Two models are needed — one for search, one for code checking.

    macOS

    brew install ollama
    brew services start ollama

    Linux

    curl -fsSL https://ollama.com/install.sh | sh
    ollama serve &

    Windowsdownload from ollama.com

    Pull the embedding model. The code-checking model is chosen during init:

    ollama pull nomic-embed-text   # required for search
    ollama pull llama3.2           # or whichever model you plan to use

    Create the database

    createdb memory_core
    psql -U $(whoami) -d memory_core -f setup.sql

    setup.sql:

    CREATE EXTENSION IF NOT EXISTS vector;
    
    CREATE TABLE IF NOT EXISTS memories (
      id           BIGSERIAL PRIMARY KEY,
      type         TEXT NOT NULL,
      scope        TEXT NOT NULL DEFAULT 'project',
      architecture TEXT,
      project_name TEXT,
      title        TEXT,
      content      TEXT NOT NULL,
      reason       TEXT,
      tags         TEXT[] DEFAULT '{}',
      embedding    vector(768),
      created_at   TIMESTAMP DEFAULT now()
    );
    
    CREATE INDEX IF NOT EXISTS memories_embedding_idx
      ON memories USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);
    CREATE INDEX IF NOT EXISTS memories_architecture_idx ON memories (architecture);
    CREATE INDEX IF NOT EXISTS memories_scope_idx ON memories (scope);

    Quick start

    # 1. Go to your project
    cd my-api
    
    # 2. Initialize — verifies connections, picks your model, generates config files
    npx @shahmilsaari/memory-core init
    
    # 3. Load 281 predefined best-practice rules
    npx @shahmilsaari/memory-core seed

    That's it. Every AI agent in your project now has your rules.


    Commands

    init — Set up a project

    npx @shahmilsaari/memory-core init

    Walks you through:

    • PostgreSQL connection URL — tested live, retries until connected
    • Ollama URL — tested live, retries until reachable (used for embeddings)
    • Code-checking provider — Ollama (local), OpenAI, Anthropic, or MiniMax
    • Code-checking model — picked from a list, verified before continuing
    • Project name, type, architecture, language
    • Which agents to generate files for — multi-select, all pre-checked, Space to deselect — saved to .memory-core.json
    • Hook mode — advisory (logs violations, never blocks) or strict (blocks commits)
    • Whether to enable caveman mode (optional token saver)

    Generates config files for every selected AI agent, saves your choices to .memory-core.json, and automatically adds all generated files to .gitignore under a # memory-core generated files block.

    At the end, the banner shows live ✓/✗ status for PostgreSQL and Ollama so you know everything is working.


    sync — Refresh all agent files

    After saving new memories, regenerate every agent file to include them.

    npx @shahmilsaari/memory-core sync

    Multi-selects which agents to sync (pre-checked from your .memory-core.json config). Skips files that haven't changed and reports how many were updated vs already up to date:

      3 updated, 11 already up to date

    remember — Save a decision

    Made a decision your team should never forget? Save it.

    npx @shahmilsaari/memory-core remember "Controllers must never call the database directly"

    It will ask you why — that reason gets stored alongside the rule and shown to AI agents and developers when a violation is caught.

    With flags (skip the prompts):

    npx @shahmilsaari/memory-core remember "Use DTOs for all API responses" \
      --type rule \
      --scope global \
      --reason "Raw DB entities expose internal schema and sensitive fields" \
      --tags "api,dto"
    Flag Options Default
    --type decision rule pattern note decision
    --scope global project project
    --reason any text asked interactively
    --tags comma-separated none

    search — Find a rule or decision

    npx @shahmilsaari/memory-core search "error handling"
    npx @shahmilsaari/memory-core search "auth strategy" --limit 10

    Uses AI search — finds related rules even if you don't use the exact words.


    seed — Load predefined rules

    281 best-practice rules across all supported architectures, each with a plain-English reason explaining why the rule exists.

    npx @shahmilsaari/memory-core seed                              # all architectures
    npx @shahmilsaari/memory-core seed --arch clean-architecture   # one only
    npx @shahmilsaari/memory-core seed --force                     # re-seed existing

    watch — Catch violations as you type

    npx @shahmilsaari/memory-core watch

    Runs in the background and checks each file the moment you save it. You see violations immediately — before you even think about committing.

      archmind watch — real-time rule enforcement
    
      watching: /your/project
      model:    llama3.2
      rules:    24
      ctrl+c to stop
    
      [10:42:11] saved: src/controllers/user.ts
    
      ✗ 1 violation in src/controllers/user.ts
    
      [1] src/controllers/user.ts:34
          Rule:   Thin controllers — business logic belongs in services
          Why:    Logic in controllers cannot be reused from other entry points
          Issue:  Password hashing inside the route handler
          Fix:    Move to UserService.hashPassword()

    Options:

    npx @shahmilsaari/memory-core watch --path src/   # watch a specific folder only
    npx @shahmilsaari/memory-core watch --verbose     # show extra details

    Only checks source files — ignores node_modules, dist, config files, JSON, etc.


    check — Manual check (for CI)

    npx @shahmilsaari/memory-core check --staged           # check staged files
    npx @shahmilsaari/memory-core check --staged --verbose # with extra detail

    Same as the pre-commit hook. Use this in CI/CD pipelines.


    hook install — Install the pre-commit hook

    npx @shahmilsaari/memory-core hook install             # advisory mode (default)
    npx @shahmilsaari/memory-core hook install --advisory  # logs violations, never blocks
    npx @shahmilsaari/memory-core hook install --strict    # blocks commits on violations

    Installs a git pre-commit hook in the current project. Every time you run git commit, your code is checked against your architecture rules.

    Advisory mode (default): violations are logged so you can see them, but the commit always goes through. Useful for getting used to the rules without disrupting your flow.

    Strict mode: violations block the commit entirely. You see exactly what's wrong and how to fix it:

      ✗ 2 rule violations found — commit blocked
    
      [1] src/controllers/user.ts:32
          Rule:   Thin controllers — business logic belongs in services
          Why:    Logic in controllers cannot be reused from other entry points
                  — it gets siloed and duplicated across handlers
          Issue:  Password validation logic inside route handler
          Fix:    Move to UserService.validateCredentials()
    
      [2] src/domain/user.entity.ts:5
          Rule:   Domain has zero external imports
          Why:    Framework imports tie business logic to infrastructure
          Issue:  Imports 'typeorm' directly
          Fix:    Define IUserRepository interface in domain/
    
      To bypass: git commit --no-verify
      To save as memory: memory-core remember "<lesson>"

    The hook mode is chosen during init — no separate step needed unless you want to change it later.

    npx @shahmilsaari/memory-core hook uninstall   # remove the hook

    list — List memories from the database

    npx @shahmilsaari/memory-core list

    Shows all stored memories. Filter the results:

    npx @shahmilsaari/memory-core list --type rule
    npx @shahmilsaari/memory-core list --scope global
    npx @shahmilsaari/memory-core list --arch clean-architecture
    npx @shahmilsaari/memory-core list --limit 50
    Flag What it does
    --type <type> Filter by type: decision rule pattern note
    --scope <scope> Filter by scope: global project
    --arch <architecture> Filter by architecture profile
    --limit <n> Max results (default 200)

    remove — Delete a memory

    npx @shahmilsaari/memory-core remove <id>

    Deletes a memory by its ID. Get the ID from list or search.


    edit — Edit a memory

    npx @shahmilsaari/memory-core edit <id>

    Opens the memory interactively so you can update its content, reason, tags, type, or scope.


    export — Export memories to a file

    npx @shahmilsaari/memory-core export
    npx @shahmilsaari/memory-core export --output path/to/my-rules.json

    Exports all memories from the database to memories.json in the project root (or the path you specify). Makes your rules portable and version-controllable — commit the file alongside your code.


    import — Import memories from a file

    npx @shahmilsaari/memory-core import
    npx @shahmilsaari/memory-core import --file path/to/my-rules.json
    npx @shahmilsaari/memory-core import --url https://example.com/team-rules.json

    Imports memories into the local database. Skips duplicates by content hash — safe to run more than once.

    Flag What it does
    --file <path> Import from a custom local file path
    --url <url> Import from a remote URL

    ignore — Mark false positives

    npx @shahmilsaari/memory-core ignore "controllers may import prisma directly in migration scripts"

    Saves a pattern so the hook and watcher never flag it again. Useful for intentional exceptions to a rule.

    npx @shahmilsaari/memory-core ignore --list          # show all saved ignore patterns
    npx @shahmilsaari/memory-core ignore --remove <id>   # delete an ignore pattern

    ci-setup — GitHub Actions integration

    npx @shahmilsaari/memory-core ci-setup

    Generates .github/workflows/memory-core.yml. Adds a PR check that runs your architecture rules on every pull request — same checks as the local hook, enforced in CI.


    stats — Violation counters

    npx @shahmilsaari/memory-core stats

    Shows which rules fire most often and which files have the most violations. Useful for spotting systemic issues in the codebase.


    reset — Remove all generated files

    npx @shahmilsaari/memory-core reset              # remove all generated files + .memory-core.json
    npx @shahmilsaari/memory-core reset --soft       # keep config and DB, remove only generated files
    npx @shahmilsaari/memory-core reset --db         # also drop the memories table from the database

    Cleans up everything memory-core created. Use --soft if you want to re-run init without losing your saved memories.


    global — Apply rules to every project

    npx @shahmilsaari/memory-core global

    Writes your rules to the global config of each AI agent — so they follow your rules in every project on your machine, not just the current one.

    Agent Where it writes
    Claude Code ~/.claude/CLAUDE.md
    GitHub Copilot VS Code settings.json
    Cursor ~/.cursor/rules/memory-core.mdc
    Cline VS Code settings.json
    Continue.dev ~/.continue/config.json
    Aider ~/.aider.conf.yml
    Zed AI ~/.config/zed/settings.json
    Windsurf ~/.windsurf/rules/memory-core.md

    Supported agents

    Agent File generated
    Claude Code CLAUDE.md
    GitHub Copilot .github/copilot-instructions.md
    Cursor .cursorrules + .cursor/rules/memory-core.mdc
    Windsurf .windsurfrules
    Cline .clinerules
    Roo Code .roo/rules/memory-core.md
    Aider .aider.conf.yml
    Continue.dev .continue/config.json
    Devin DEVIN.md
    Amazon Q .amazonq/dev/guidelines.md
    Gemini Code Assist .gemini/styleguide.md
    Zed AI .zed/settings.json
    JetBrains AI .idea/ai-instructions.md
    OpenHands AGENTS.md

    Plus shared files: AI_RULES.md, ARCHITECTURE.md, PROJECT_MEMORY.md


    Architecture profiles

    Pick the one that matches how your project is structured.

    Backend

    Profile Use when…
    Clean Architecture You want strict separation between domain, application, and infrastructure
    Modular Monolith You're building feature modules that might become microservices later
    MVC Standard web app with controllers and services
    Hexagonal You want ports and adapters for maximum testability
    Go REST API Go backend API with idiomatic error handling and clean package structure
    Laravel Laravel with service-repository pattern
    NestJS Modules, guards, pipes, DTOs, repository pattern

    Frontend

    Profile Use when…
    React Functional components, hooks, React Query, Zustand
    Vue 3 Composition API, Pinia, composables
    Angular Standalone components, signals, OnPush strategy
    Svelte Svelte 5 runes, SvelteKit load functions, snippets
    Nuxt 3 Fullstack Vue with SSR
    React Native Mobile apps

    Fullstack projects get both sections in every generated file.


    Caveman mode (optional)

    Cuts AI response length by 65–75% by removing filler words. Opt in during init.

    Level What it does
    lite Professional and concise
    full Caveman-style short answers
    ultra Absolute minimum words

    Day-to-day workflow

    # Starting a new project
    cd my-api
    npx @shahmilsaari/memory-core init   # verifies connections, picks model, selects agents, installs hook
    npx @shahmilsaari/memory-core seed   # load 281 best-practice rules
    
    # Made an architectural decision? Save it.
    npx @shahmilsaari/memory-core remember "All auth goes through middleware, never in controllers" \
      --type decision --scope global
    
    # Refresh agent files after saving new memories
    npx @shahmilsaari/memory-core sync
    
    # Not sure how something was decided? Search.
    npx @shahmilsaari/memory-core search "caching strategy"
    
    # See what rules are saved
    npx @shahmilsaari/memory-core list --type rule
    
    # Export rules to version control
    npx @shahmilsaari/memory-core export
    
    # Commit code → hook checks it automatically before committing
    git commit -m "add user endpoint"

    Environment variables

    memory-core creates .memory-core.env automatically during init. You can also set these manually:

    Variable Required Default What it does
    DATABASE_URL Yes PostgreSQL connection string
    OLLAMA_URL No http://localhost:11434 Where Ollama is running (used for embeddings)
    OLLAMA_MODEL No nomic-embed-text Model used for search (embeddings) — always Ollama
    CHAT_PROVIDER No ollama Provider for code checking: ollama, openai, anthropic, minimax
    CHAT_MODEL No llama3.2 Model used for code checking — chosen during init
    CHAT_API_KEY No API key for OpenAI / Anthropic / MiniMax (not needed for Ollama)
    OLLAMA_CHAT_MODEL No llama3.2 Legacy alias for CHAT_MODEL when provider is ollama

    Troubleshooting

    extension "vector" is not available pgvector isn't installed for your PostgreSQL version. Follow the pgvector install steps above.

    Ollama not running — skipping rule check Start Ollama: brew services start ollama (macOS) or ollama serve (Linux).

    Chat model "llama3.2" not found Run ollama pull llama3.2. Or switch provider/model by updating CHAT_PROVIDER and CHAT_MODEL in .memory-core.env.

    Using an API key instead of Ollama for code checking During init choose OpenAI, Anthropic, or MiniMax when prompted for the check provider. Or set manually in .memory-core.env:

    CHAT_PROVIDER=openai
    CHAT_MODEL=gpt-4o
    CHAT_API_KEY=sk-...

    Embeddings always use Ollama (nomic-embed-text) regardless of provider.

    DATABASE_URL is not set Run npx @shahmilsaari/memory-core init — it will create the .memory-core.env file for you.

    createdb: role does not exist

    createuser -s $(whoami)

    Hook is flagging JSON or config files It won't — the hook only checks source code files: .ts .tsx .js .jsx .py .php .rb .go .java .cs .swift .kt .rs .vue .svelte. Everything else is skipped automatically.

    Hook is flagging something that's intentional Save an ignore pattern: npx @shahmilsaari/memory-core ignore "your exception here". The hook and watcher will never flag it again.


    Roadmap

    Feature
    Watch mode — real-time violation alerts on save
    Model picker — choose your Ollama model during init
    Connection validation — PostgreSQL and Ollama verified during setup
    Svelte 5 / SvelteKit profile and 37 rules
    NestJS profile and 39 rules
    Hook auto-prompt — hook mode offered during init, no separate step needed
    CI/CD — ci-setup generates GitHub Actions workflow for PR enforcement
    Violation stats — see which rules fire most and which files break most
    Agent selection — choose which agents to generate files for during init
    Export / import — portable memories.json for version control and team sharing
    List / remove / edit — full CRUD for stored memories
    False positive tagging — ignore command saves exceptions for hook and watcher
    Reset command — clean up generated files and optionally drop the DB table
    Test suite — Vitest smoke tests for all core commands and providers
    Multi-provider code checking — Ollama, OpenAI, Anthropic, MiniMax
    Context-aware retrieval — surface the most relevant rules for the file being edited
    Model guidance during init — recommend a model based on machine specs
    --debug flag — verbose output for diagnosing hook and watcher issues
    Violation → rule pipeline — auto-suggest a new rule when the same violation repeats
    Rule analytics dashboard — visual breakdown of rule coverage and violations
    Team sync — shared database so the whole team works from the same rule set

    License

    MIT

    Built by Shahmil Saari