Repository avatar
AI Tools
v1.1.1
active

geoplana

io.github.yungkei/geoplana

Universal external memory for AI agents across sessions and context compaction

Documentation

Geoplana

Universal external memory for AI agents
Two-layer storage · Lossless archive · Compaction rescue · Cross-agent persistent memory

中文

npm version license node version typescript


Like the planarian worm (named for Geoplana, the land planarian genus): even when context gets "severed" — context compaction, session end, model switch — memory fully regenerates. Local, persistent memory for AI coding agents such as opencode and claude code.

Why geoplana?

Your agent forgets. Twice. When a long coding session hits the context limit, agents compact history into an LLM summary — and research (Compact-Bench) shows LLM summaries retain at most ~16% of the structured details that recur in later requests. When the session ends, everything not written down is gone entirely. geoplana closes both gaps:

  • Before compaction, the full transcript is snapshotted into a lossless archive — nothing is ever summarized away. Independent work on a plain-text log plus search reached 95–97% recall vs ≤21% for lossy baselines (GrepMem)
  • Structured extraction (deterministic rules, not LLM summaries) additionally curates the details worth keeping: in the same benchmark, plain mechanical extraction retained ~79% of recurring details — paths, commit IDs, error types, URLs, config values — versus ~16% for LLM summaries (~5×)
  • Cross-session, cross-agent: the same memory follows you from opencode to claude code to any MCP-compatible agent — and it survives model switches too

Built to be trusted with years of memories.

  • Local-first & private: single SQLite file, zero cloud dependency; <private> content never touches disk
  • Search in any language: full-text search that actually works for Chinese, Japanese, Korean, Thai, Russian, Arabic…
  • Self-managing storage: hot/warm/cold tiers (gzip shrinks data to ~25%), size quota, forgetting-curve eviction — memories you actually reuse never fade
  • You decide, not the AI: conflicting memories are flagged and resolved by you (memory_resolve), never silently merged or deleted
  • Rules survive compaction: one study found the first compaction summary already drops ~1/3 of a task's constraints, and real user sessions lost "how the agent should work" rules ~6× more often than build specs (Salle et al., 2026) — geoplana keeps such rules as pinned memories across sessions
  • Upgrade-safe by design: additive-only schema migrations, automatic pre-migration backups, and older versions refuse to write to newer databases rather than risk corruption

Adopt in minutes. One command wires it into claude code (pure config) or opencode (thin shim). Also usable as a typed npm library in your own agent.

Features

  • Two-layer storage: curated memories + lossless episode archive. SQLite + FTS5 with multilingual full-text search (CJK/Korean/Thai/Russian/Arabic/...), fully local, zero external dependencies
  • Local query expansion: paraphrased, cross-language and morphological queries still hit — a curated English/Chinese concept table plus intent-scoped terms widen the query before matching (no model, no network). Two-character Chinese words match too, and literal matches always rank above expansion-only ones
  • Automatic capture: decisions, preferences and errors the user states are extracted with deterministic rules; tool activity stays in the lossless episode archive; <private> content never touches disk
  • Compaction rescue: full conversation snapshot archived before the agent compacts its context
  • Lifecycle management: hot/warm/cold retention tiers (gzip compression + archive export), storage quota, forgetting-curve eviction, and GC cleanup of activity-log memories
  • Evidence-based recall quality: every search is logged (query, full search input, scoring-parameter snapshot, hit scores, expansion provenance, hits tagged with branch and scope), outcomes are written back onto the query hits that surfaced them, and memory_stats reports the zero-hit rate, per-query used/useless rates and label coverage, LIKE/expansion contribution, scope hit-share, per-type value (decisions read and rated useful), extraction and conflict-resolution outcomes, GC activity and a noise audit (D0-D3)
  • Usage assurance: geoplana setup writes a memory protocol into the agent's instructions file (AGENTS.md / CLAUDE.md) telling it when to search, when to save, and how to handle conflicts
  • Conflict resolution: memory_save returns similar existing memories as conflicts instead of silently overwriting; the agent asks the user, then calls memory_resolve (keep-new / keep-old / keep-both)
  • MCP tools: memory_save / memory_search / memory_get / memory_update / memory_delete / memory_list / memory_capture / memory_context / memory_resolve / memory_feedback / memory_stats

Install

npm install -g @yungkei/geoplana

Data lives in ~/.geoplana/geoplana.db (override with the GEOPLANA_HOME env var).

Working on geoplana itself:

git clone https://github.com/yungkei/geoplana.git
cd geoplana
npm install
npm run build
npm link        # makes the geoplana command globally available

Quick start

claude code (pure config, zero code)

geoplana setup claude-code

Writes hooks into ~/.claude/settings.json: inject memories at session start → capture every turn → snapshot rescue before compaction.

opencode (bridge shim)

geoplana setup opencode

Copies the shim plugin to ~/.config/opencode/plugins/ and registers the MCP server in opencode.json (other settings are preserved):

{ "mcp": { "geoplana": { "type": "local", "command": ["geoplana", "mcp"] } } }

The shim is dual-generation — one file adapts at load time to both the opencode V1 (≥1.16.2) and V2 plugin APIs, so there is no version-specific artifact to choose. setup detects the installed opencode generation and reports compatibility.

setup also stamps the server entry with the fingerprint of the installed build. The MCP server is a long-lived process, so after an upgrade the running one would keep serving the old code; the stamp makes opencode restart it onto the new build. Re-run geoplana setup opencode after every upgrade (/reload in opencode works too). geoplana doctor prints the installed build, memory_stats reports the build the running server was started with — if the two differ, the server is stale.

Any MCP agent

{
  "mcpServers": {
    "geoplana": { "command": "geoplana", "args": ["mcp"] }
  }
}

Without a global install, run the published package directly:

{
  "mcpServers": {
    "geoplana": { "command": "npx", "args": ["-y", "@yungkei/geoplana", "mcp"] }
  }
}

CLI

geoplana save --namespace global --type decision --content "use Valkey for caching" --importance 0.9
geoplana search "caching decision" [--namespace a,b] [--limit 20]
geoplana list [--namespace a,b] [--type decision]      # alias: ls
geoplana get <id> / update <id> / delete <id> [--dry-run]   # aliases: view / rm
geoplana resolve --new-id x --old-id y --action keep-new
geoplana context --namespace global,project:/repo
geoplana capture --namespace session:abc --kind message --content "..." --session-id abc

geoplana episodes list [--session s1] [--kind note]    # browse the archive layer
geoplana episodes get <id>                             # compressed episodes decompress transparently
geoplana export --output backup.jsonl.gz [--layer all] # versioned backup
geoplana import backup.jsonl.gz [--dry-run]            # existing ids are skipped

geoplana stats            # storage usage, memory mix, namespace spread
geoplana stats --perf     # plus per-event latency percentiles and outcome counters
geoplana stats --perf --event search,hook:recall:hits   # only these metric events
geoplana gc [--dry-run]   # retention GC: compress / export / evict
geoplana migrate [--dry-run]   # re-scope existing memories into the shared scope
geoplana doctor           # schema version & integrity check
geoplana mcp              # run the MCP server over stdio
geoplana hook <event>     # universal hook handler (called by agent hooks)

Memory scopes

Every memory lives in one of three scopes. The scope decides who can read it.

scopenamespacevisible toholds
globalglobalevery project and sessionrules about how to work
projectproject:<path>every session of that repositorydecisions and preferences
sessionsession:<id>that one sessioncommands run, files changed, snapshots

A session reads global + its project + itself.

Auto-extraction routes by durability, so a decision survives the conversation that produced it:

  • decisions and preferences the user stated go to the project scope
  • instructions go to the global scope
  • facts, errors and context stay in the session scope - they are the activity log, not shared knowledge

Two rules keep the shared scopes clean:

  • only complete statements are promoted. A fragment ("改为复制 |") stays in the session scope, because a shared scope is read by every later session
  • only the user's own words are promoted. The agent narrating its work ("改为路径无关:...") documents a task, it does not decide.

Project paths are normalized (D:\repo and D:/repo are one namespace), and the project directory is recorded on every captured episode.

geoplana migrate applies the same rules to memories captured before the rules existed: it promotes the statements that qualify, normalizes project namespaces, and reports everything it skipped and why. It never deletes.

geoplana migrate --dry-run   # preview
geoplana migrate             # apply

geoplana stats reports durableScope:

  • shared - durable memories in a global or project scope, read by every later session
  • locked - durable memories that qualify for sharing but still sit in a session scope. This is the backlog geoplana migrate would move
  • sessionOnly - every durable memory in a session scope, including the ones that do not qualify and are meant to stay there

Configuration

~/.geoplana/config.json (everything optional, sensible defaults):

{
  "dbPath": "~/.geoplana/geoplana.db",
  "embedding": { "provider": "none" },
  "capture": { "maxExtractChars": 20000 },
  "recall": { "intent": true, "expansion": true, "limit": 3 },
  "retention": {
    "hotDays": 30,
    "snapshotHotDays": 90,
    "coldDays": 365,
    "evictThreshold": 0.02,
    "protectRecentDays": 14,
    "maxStorageMb": 500,
    "autoGc": true
  }
}
OptionDescription
recall.intentClassify each recall prompt's intent (keyword heuristics, no LLM) and soft-boost matching memory types; false disables the boost
recall.expansionWiden search queries with concept synonyms and intent-scoped terms (local, no model); false disables it
recall.limitMemories returned per recall injection
hotDaysDays episodes stay fully searchable (hot tier)
coldDaysDays compressed episodes are kept; -1 = keep forever, 0 = export immediately
maxStorageMbDB size quota; GC escalates when exceeded
evictThresholdForgetting-curve eviction threshold (pinned memories are never evicted)
autoGcRun GC automatically when the MCP server starts
metrics.queryLogLog every search as evidence (query, namespaces, branch-tagged hits) for the recall quality report; false disables it

Environment variables: GEOPLANA_HOME (data directory), GEOPLANA_CMD (command path used by agent shims), GEOPLANA_RECALL=1 (opencode per-turn recall), GEOPLANA_DEBUG=1 (debug logs).

Use as a library

geoplana is also an npm package (@yungkei/geoplana) — third-party programs can embed it directly:

npm install @yungkei/geoplana
import { Geoplana, createStorage, createMemoryStorage } from "@yungkei/geoplana"

const geoplana = new Geoplana(createStorage("/path/to/geoplana.db"))

geoplana.memories.save({ namespace: "global", type: "decision", content: "Use Valkey for caching" })
const hits = geoplana.search.search({ query: "caching", includeEpisodes: false })
const bundle = geoplana.context.build({ namespaces: ["global"] })

geoplana.close()

All core services are typed and exported: memories / search / capture / context / retention. To plug in a custom storage engine, implement the Storage interface and pass it to the Geoplana constructor.

Development

npm test            # unit tests
npm run typecheck   # type checking
npm run lint        # biome lint + format check
npm run check:i18n  # CLI/i18n guard
npm run build       # build to dist/

License

Apache-2.0 © 2026 yungkei

NPM
@yungkei/geoplana
Install Command
npm install @yungkei/geoplana
Runtime: npx