agentleFS
vvooki-sysvvooki-sys/loomem/CLAUDE.md

loomem

CLAUDE.md4 starsChanged 4 days agoApache-2.0View on GitHub

Hard rules every AI assistant (Claude Code, Cowork, Copilot, Cursor, …) must follow when touching this repo. Some are enforced by CI; the rest are enforced in review. Deep rationale, complexity carve-outs and edge cases live in docs/agent-conventions.md — this file stays short on purpose, because it loads into context every session. What Loomem is. An open-core, single-user memory engine (Apache-2.0, vvooki-sys/loomem), forked from Engram. The repo is public — assume external readers and their agents. Public positioning: "the open-source…

The file

We split this CLAUDE.md into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Binary location: if a maintainer's global ~/.cargo/config.toml redirects target-dir, release binaries are not under ./target/release.

    line 46
  2. Very specific:

    Dependencies: no new crate without justification (why it can't be ~50 lines in-tree) + cargo audit clean + recent maintenance.

    line 72
  3. Distinctive:

    Never recreate a lost cost register or evidence file: If a frozen artifact or register is missing, report it.

    line 141
  4. Distinctive:

    Thresholds are frozen per campaign: Never lower a decision threshold, a selector threshold or a denominator to make a result pass.

    line 143

≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md — rules for AI code generators in the Loomem repo

Hard rules every AI assistant (Claude Code, Cowork, Copilot, Cursor, …) must follow when touching this repo. Some are enforced by CI; the rest are enforced in review. Deep rationale, complexity carve-outs and edge cases live in docs/agent-conventions.md — this file stays short on purpose, because it loads into context every session.

What Loomem is. An open-core, single-user memory engine (Apache-2.0, vvooki-sys/loomem), forked from Engram. The repo is public — assume external readers and their agents. Public positioning: "the open-source context layer for LLM agents." It is memory-only (the memory_* MCP tool set, no file layer) and single-user (no accounts, RBAC, SSO, multi-tenancy). Those two product boundaries are frozen (see § Product boundaries).


Router — read the subset that applies

  • Changing Rust code → § Five hard rules + § Build & run + § Repo map + § Rust rules.
  • Docs / landing / content / GEO → § Docs & site + hard rule 5 (surgical). A docs task never touches Rust.
  • Dashboard (loomem-dashboard/, React SPA) → § Build & run (dashboard bullet) + hard rule 5. A dashboard task touches no Rust beyond loomem-server/src/spa.rs.
  • Cutting a release → § Releases.
  • Any multi-step task, or a session that writes code → § Agent workflow (worktrees, delegation, cleanup).
  • Benchmarks / evaluation → § Benchmarks & evaluation.
  • Always → § Five hard rules, especially live-state (rule 4), product boundaries (rule 3), secrets (rule 1).

Five hard rules (never break these)

  1. Secrets & personal data never get committed. No API keys, tokens, passwords, production endpoints — and no real names or private data in entities.toml / synonyms.toml (gitignored; only *.example variants are tracked). Any user content that gets persisted anywhere, including derived/audit fields like original_content, must pass through sanitizer + the PII filter — not just the visible content. .gitleaks.toml catches some leaks; you are the first gate. See something sensitive in a diff → stop and tell the user.
  2. The local gate must be green. For every change CI sends to the Rust jobs, cargo fmt --check && cargo clippy --workspace -- -D warnings is byte-identical to CI and to the pre-commit hook. If it isn't green, the work isn't done. Never use --no-verify.
  3. Product boundaries are frozen. Loomem is memory-only (the file layer was removed in loomem/005 — do not re-add file tools, parsers, or /v1/files) and single-user (no accounts, RBAC, SSO, magic-link, transactional email, or multi-tenant "workspaces"; streams organize one person's memory, they are not tenancy). A brief asking for any of these = STOP and ask the owner (team features live in Engram).
  4. Trust live state, not memory. Cross-conversation memory (Engram/Loomem MCP, Cowork MEMORY.md) describes "what was true when written," not "what is now." Before relying on any file, function, flag, or default a memory names, verify it still exists in the repo. When memory and git log / gh pr list disagree, trust live. Likewise, docs adapt to code — never copy a value from one doc page to another; verify it against config.toml/source.
  5. Surgical and compatible changes only. Touch only what the task needs; no drive-by refactors, no "while I'm here" cleanups (report unrelated dead code, don't delete it). Match the file's existing style. And: any new field on a struct persisted to RocksDB (Chunk, ExtractionMeta, FactType, …) must be #[serde(default)], or you break deserialization of existing databases.

Build & run

Crates: loomem-core (domain + storage), loomem-server (HTTP/MCP), loomem-cli (stdio↔HTTP MCP bridge + ops), loomem-migrate (probes/migrations). Not a crate: loomem-dashboard/ (React/Vite SPA, embedded into loomem-server by rust-embed from loomem-dashboard/dist/, see loomem-server/src/spa.rs).

  • loomem-core and loomem-server compile RocksDB (C++) and need libclang. Light/sandboxed environments often can't build them — don't assume a clean cargo build everywhere. CI installs libclang-dev.
  • Dashboard build order: front end first, then cargo. cd loomem-dashboard && npm ci && npm run build writes dist/; cargo build -p loomem-server then embeds it. With an empty dist/ the server still compiles and / answers 404. dist/ is gitignored — never commit it. The Rust gate does not cover the SPA: CI has a separate job (npm run lint, npm test, npm run build), so run those locally before pushing dashboard changes.
  • Fail-closed startup. With the default config the server refuses to start without the local embedding model (embedding_provider = "local", no cloud fallback) and without an LLM key while LLM-backed subsystems are enabled. LOOMEM_ALLOW_KEYLESS=1 opts into degraded keyless mode (memory_ingest stores nothing, extraction off, dreaming fails; memory_store and search work). Expect this when running the server locally or in tests — don't "fix" it by weakening the check.
  • Windows: loomem-server builds and runs on Windows (LLVM for libclang, LIBCLANG_PATH; see INSTALL_WINDOWS.md). Release archives still cover Linux and macOS only.
  • loomem-cli pulls no RocksDB/Tantivy (just tokio/reqwest/clap) — it compiles in seconds. Use it for fast bridge/CLI iteration.
  • Fast feedback loop: cargo check -p <crate> and cargo test -p loomem-core --lib run in seconds. A full cargo build --workspace (release especially) is slow — don't run it in a loop.
  • macOS aarch64 release gotcha: the release build SIGSEGVs rustc (LLVM SLP vectorizer, ThinLTO) without -C no-vectorize-slp. That flag is already pinned for the Mac target in .cargo/config.toml — don't remove it. Linux/Docker/Railway are unaffected.
  • Binary location: if a maintainer's global ~/.cargo/config.toml redirects target-dir, release binaries are not under ./target/release. Check the effective target dir before hunting for a binary.

Repo map (where things live)

  • Storage / domain: loomem-core/src/storage.rs (RocksDB, Chunk), tantivy_index.rs, hybrid_search.rs, graph/, crypto/ (+ encrypt_backfill/) for at-rest encryption.
  • LLM prompts & extraction: loomem-core/src/llm.rs, memory_extractor.rs (extraction prompt), dream.rs, consolidation.rs, advisor.rs.
  • LLM provider routing: loomem-core/src/llm_provider.rs. Every chat call goes through the active llm.provider (LlmConfig::active_provider() → ResolvedProvider::chat_request / send_chat). Never hardcode a provider URL or a model name in new code — read both from config. OpenAI is not assumed: the default chat model is gpt-6-luna through the built-in openai provider, with max_completion_tokens / reasoning_effort coming from the [llm.providers.openai] entry in config.toml (the previous default gpt-4.1-mini is retired by OpenAI on 2027-01-14); check config.toml for what is live. Use a pay-per-token API for the engine and evaluation, not a personal coding subscription endpoint: those terms forbid automation. Embeddings are separate (embedding_provider, default local).
  • MCP surface: loomem-server/src/mcp/ — dispatcher.rs (tool dispatch, source of truth for the tool set), router.rs, handler.rs, tools.rs. Canonical handshake text: loomem-server/mcp_instructions.md.
  • HTTP handlers: loomem-server/src/handlers/ (search.rs, ingest.rs, admin.rs, purge.rs, …).
  • Config: config.rs composes per-module sub-configs (manifest/config.rs, access_audit/config.rs, …). Runtime config: config.toml.

Rust rules

Full tables, carve-outs, and the "aspirational vs actually enforced" breakdown are in docs/agent-conventions.md. The short version:

  • Complexity (review-enforced, not CI): per function CC ≤ 10, COG ≤ 15, SLOC ≤ 100, args ≤ 6; per file SLOC ≤ 700, MI ≥ 40. Already-over files must not get worse. Before adding an if to a CC ≥ 10 function, stop and extract. (There is no check-complexity.sh yet — a critic pass verifies with lizard.)
  • Error handling: no .unwrap() / .expect() / panic! / todo! / unimplemented! in production paths (test/bench/example code and a final main() are exempt). Propagate with ? and .context("…"). Domain errors → thiserror (in loomem-core); handler errors → anyhow.
  • Numeric conversions: no as for numeric casts — use u32::try_from(x).context(…)?. as only for documented // truncation intentional: …, FFI, or same-type.
  • Embedding dim-guard: embedding_dim must match the provider (local/multilingual-e5-small = 384, openai/text-embedding-3-small = 1536). Read it from config; a mismatch with the existing index corrupts search.
  • Layers (non-negotiable): [HTTP/MCP handler] → [loomem-core domain] → [storage/adapter]. Handlers don't call storage directly; storage doesn't import HTTP types; loomem-core doesn't import axum (inject I/O traits instead).
  • Config: one *Config struct per module, declared next to its code; the root Config only composes sub-configs. config.toml is "all settings required, no hardcoded defaults" — new param goes in both config.toml and the loader.
  • Tests: new public fn → unit test; new handler/MCP tool → integration test with a JSON fixture. No storage mocks in integration tests (use tempdir/in-memory trait impls). Deterministic only (no sleep > 1ms, no system clock without a Clock trait). CI runs cargo test --workspace --lib --bins (no integration tests); locally, run what the change's test level requires (§ Agent workflow).
  • Dependencies: no new crate without justification (why it can't be ~50 lines in-tree) + cargo audit clean + recent maintenance. Pin versions centrally in [workspace.dependencies].

Docs & site

A docs/landing/content task never touches Rust (and never search.rs / fusion / retrieval). Where things live:

  • docs/*.md — source of truth for guide content.
  • docs/guide/*.html — hand-maintained HTML mirrors of docs/*.md. There is no generator — when you change a .md, sync the matching .html by hand.
  • docs/index.html — hand-written landing page.
  • Web-root / GEO files live under docs/ (the site root), not the repo root: docs/robots.txt, docs/sitemap.xml, docs/llms.txt, docs/llms-full.txt, docs/og-image.png, JSON-LD inside docs/index.html, docs/assets/ (banner, logo). There is no CNAME file in the repo.
  • loomem-server/mcp_instructions.md — canonical MCP handshake text.

Anti-drift (this bit earns its keep): before writing any value into docs — a default, a config key name, a behavior — verify it against config.toml or the source. Never copy a value from another docs page; page-to-page copying is the root cause of drift (we have hit: backup retention, "RRF" vs weighted fusion, provider vs embedding_provider, OpenAI vs local embedding default). A user-facing claim (clients, install steps, feature list) must be synced across all surfaces at once: README.md + docs/index.html + docs/guide/*.html + docs/*.md.

Security page is dated — keep it current. The security page (docs/SECURITY.md + its mirror docs/guide/security.html, served at loomem.ai/guide/security) carries a Last updated: YYYY-MM-DD line under the H1. Any change to its security content must bump that date — in both files, to the same value (the date of the change, not a copied old one). A pure typo/markup fix that changes no security claim may leave it; when in doubt, bump. The date lives only on the security page — don't spread it to other guide pages unless asked.

Naming canon: brand is Loomem. The category label is "context layer"; "memory" is allowed as a benefit/bridge word in marketing copy — the canonical hero is H1 "One memory. Every AI tool." with the mantra "Swap the model, switch the tool — your context follows." as sub-headline. "memory engine" stays reserved for the one-line technical/GEO definition. Team tier is "Loomem T". "Engram" never appears in public-facing copy.

Tool-set caveat: Loomem exposes the memory_* set only — the dispatcher (loomem-server/src/mcp/dispatcher.rs) is the source of truth for which tools exist; don't hardcode a count in prose that can drift. There is no file layer in Loomem. loomem.ai and try.loomem.ai are marketing/trial pages, not an engine endpoint. Never "discover" a tool set against any live server and document it as Loomem features — a hosted instance may be Engram (which does expose file_*); the dispatcher is the only truth.


Commits, releases, workflow

Commits — Conventional Commits + DCO sign-off (see CONTRIBUTING.md):

feat: add temporal filter to memory_search
fix:  handle empty stream id in purge handler
  • type: subject, imperative, ≤ 72 chars; blank line; body explains why. Sign off with git commit -s (DCO; unsigned PRs get rebased). Fixes #123 / Refs #123 to close issues.
  • Do not add Co-Authored-By: Claude unless explicitly asked.
  • A no-op delivery is valid but must be documented (one line: "NO-OP, pre-count confirms no work, because …"). Deviating from a brief needs a one-line rationale in the body.

Releases (SemVer): in one commit, bump [workspace.package] version in Cargo.toml, add a CHANGELOG.md entry, and tag vX.Y.Z. Pushing the tag triggers release.yml, which builds the dashboard SPA and then 4 targets (x86_64/aarch64 Linux, aarch64/x86_64 macOS; no Windows archive). main should never be ahead of the latest tag — tag the release commit itself.

Workflow reality: solo repo, but every change goes through a PR on a branch — docs, chore, ci and release commits included. The protect-main ruleset blocks deletion and force-push and requires the CI gate status check, so a direct push to main is rejected (checked 2026-11-22). For a release, merge the release PR and tag the resulting commit on main. The pre-commit hook (fmt + clippy) is the real local gate for Rust — install it once with scripts/install-hooks.sh (from the main checkout or any worktree; hooks are shared, so once per clone is enough). It skips commits whose staged paths CI would not send to the Rust jobs; CI runs the jobs scripts/ci-scope.cjs selects for the diff, and CI gate fails if a selected job did not succeed. Greptile reviews every PR. Before merging, address every Greptile comment: fix it, or reply on the thread with why it does not apply. Wait for the Greptile review to finish and do not enable auto-merge, which merges on green checks without waiting for review comments. Every engine PR gets an independent critic pass before merge (see § Agent workflow); for risky engine work use the numbered-cycle discipline (multi-agent-workflow-lite). Cycle artifacts are not committed. PR + critic is mandatory for external contributions.

Memory dogfooding: Claude Code/Cowork now have a loomem MCP connector pointed at the product. Don't pollute product memory with dev-chatter — use a dedicated dev stream or skip storing ephemeral build/session notes.


Agent workflow

How AI sessions work in this repo (Claude Code first; other tools follow the same intent).

  • Start from origin/main, in your own worktree. git fetch first, then cut a fresh worktree and branch from origin/main (Claude Code: under .claude/worktrees/). Run scripts/install-hooks.sh if the pre-commit hook is not installed yet. Never work in, switch branches in, or "update" a checkout you did not create — another session may be using it, and a local main can be far behind origin/main. Before trusting any audit or memory about the code, confirm which commit it was made on (rule 4).
  • Orchestrate and delegate. For anything beyond a handful of edits, the top-level session plans, splits and verifies; specialised subagents do the work: read-only exploration (fan out over independent areas), planning per item, one implementer per PR in its own worktree, an independent critic that reviews the diff without the implementer's reasoning, and CI as the verifier (§ Spend builds and CI deliberately). Independent PRs run in parallel; two implementers never touch the same files. Delegation can be hierarchical (a coordinator per work item may delegate further). Every subagent gets a self-contained brief: goal, files, constraints, definition of done.
  • Verify, don't relay. A subagent's report is a claim. Check the diff, CI and test output yourself before calling anything done.
  • Greptile is part of review. A PR is ready to merge only when CI is green, the critic is positive and every Greptile comment is resolved (fixed, or answered on the thread). After pushing fixes, wait for Greptile's re-review.
  • New behaviour lands behind a config flag, off by default and byte-identical to the current path, unless a measured A/B justifies a new default (no category may regress by 2 pp or more; see the benchmark rules below).
  • Test in proportion to the change. The paths in the diff set the level; mixed diffs take the union, unclassified paths count as ci/infra. scripts/ci-scope.cjs holds the path rules for CI and the hook; details and exceptions are in docs/agent-conventions.md.
    • presentation (docs/, top-level *.md): no local build.
    • dashboard (loomem-dashboard/): npm run lint && npm test && npm run build.
    • bench (bench/longmemeval/): tests of the changed modules and their direct importers; the full harness once before the last push only when the shared money or runner path changes.
    • rust: cargo check -p <crate> and cargo test -p <crate> (unit, bin and integration tests) for the changed crate and the crates that depend on it; CI runs no integration tests. Rust paths outside a crate (config.toml, .cargo/, toolchain files) need a full cargo test --workspace. High-risk Rust (public loomem-core API, storage and RocksDB-persisted structs, search and fusion, crypto/ and encrypt_backfill/, god files, hot-path refactors, dependencies, the evaluation feature) also needs a full cargo test --workspace once before opening the PR.
    • ci/infra (.github/, scripts/, Dockerfile, install.sh) and unclassified paths: full CI.
  • Spend builds and CI deliberately. Run your level once per push, not in a loop, and build release binaries only when the task needs them. A critic does not rerun the full suite: it reads the diff, runs the new and changed tests, and checks that they fail on the old code. CI is the verifier. Reproduce a CI failure locally before pushing a fix, batch fixes into one push (each push is a new CI run and Greptile review), and do not rerun CI without new evidence. Delete your own build outputs and temporary data directories as soon as you no longer need them; on a shared target-dir (see § Build & run), never run cargo clean, which wipes every project's cache.
  • Clean up after yourself. After a PR merges, delete its remote and local branch and remove its worktree (git worktree remove, then git worktree prune). At the end of a task, git worktree list and git branch -a show nothing of yours. Stale branches that are already merged into origin/main may be deleted; never delete someone else's unmerged branch or worktree — list it for the owner instead (last commit date + PR state).
  • Owner overrides. The maintainer may keep a local, gitignored CLAUDE.local.md next to this file with owner-specific permissions (e.g. merge/release autonomy, cost limits). Where present it refines this section; it never relaxes the five hard rules.

Benchmarks & evaluation

  • No paid model calls without an approved budget. Dry-runs, smoke tests and failure tests run offline: a loopback stub provider, outbound traffic blocked, temporary data dirs, random ports (never the product port 3035). A paid run starts only after the owner approves a cost sheet, and only through a runner that reserves cost in a durable journal before each HTTP request and stops at the limit.
  • Never recreate a lost cost register or evidence file. If a frozen artifact or register is missing, report it; a new campaign gets a new register with an explicit limit.
  • Disclose the reader and judge. gpt-4.1 is no longer available, so earlier gpt-4.1 numbers are not directly comparable with new runs. Publish per-type results, prompts, config, tokens-to-reader and the exact reader/judge models; ≥ 90 % claims need two seeds. Model aliases without a dated snapshot must be recorded from each response and a run stops if the model changes.
  • Thresholds are frozen per campaign. Never lower a decision threshold, a selector threshold or a denominator to make a result pass; a change needs a new, versioned policy approved before the next measurement.

When in doubt — stop and ask

  • Breaking up a function > 500 SLOC (architectural, not operational).
  • Touching a god file (large inherited files; hottest are handlers/search.rs, core/storage.rs, handlers/admin.rs, mcp/dispatcher.rs, server/main.rs, core/graph/mod.rs — run wc -l for current sizes). Each modification needs a Critical file rationale: line in the commit (why it's minimal-risk: doesn't change control flow/behavior + what was verified).
  • Touching crypto / at-rest encryption (loomem-core/src/crypto/, encrypt_backfill/) — a mistake here loses or leaks data.
  • Adding a dependency, or being unsure which layer (handler / core / storage) code belongs in.
  • An existing test starts failing and you don't understand why.
  • Code you don't understand that you're tempted to leave alone — don't leave it, ask.

This file is load-bearing: it shapes every agent session. Treat changes to it (and to docs/agent-conventions.md) as deliberate, not drive-by — especially for external contributors.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.