Skip to content

About

Permanent memory OMP plugin based on OptMem

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

omp-perma-memory

One chat that never ends, for omp. A port of the memory of UniiChat (Victor Taelin), following its source (Memory.ts, AskAI.ts, prompt.txt): the chat itself is the memory.

  • Every message of the main session (your words, replies, tool calls with their results) is logged word for word, forever, across every omp session and restart.
  • In the background, a cheap model compresses the log into a binary tree of one-line summaries (512 bytes each): each message becomes a line, two adjacent lines merge into one, and so on.
  • Each turn starts fresh. The model sees the system prompt, the view (lines covering the whole chat, recent ones fine and old ones coarse, 64-128 KB) and then only the current turn.
  • When a line is too vague, the model calls zoom(id, n) to open it into the two lines it was made from, down to zoom(id, 1) for the message whole. date(id) gives a message's date.

The context stays a constant size, nothing is ever lost, nobody compacts by hand, and the view is read from the prompt cache.

Install

omp plugin install github:btudorache/omp-perma-memory#v0.2.0  # a release; without #v0.2.0: latest main
omp plugin link /path/to/omp-perma-memory                     # a local clone (edits need no reinstall)
omp -e /path/to/omp-perma-memory/src/index.ts                 # one run, without installing

Built against omp 18.8.5 (it uses the extension API and omp's model and settings modules). No build step and no dependencies at runtime.

Upgrading from 0.1: the first start moves chat.db into the layout below and keeps it as chat.db.migrated. Close every omp running 0.1 first: while one holds chat.db, 0.2 runs without memory and says so.

Configuration

Setting Env var Default Meaning
dir PERMA_MEMORY_DIR <agent dir>/perma-memory Where the chat lives. One chat per directory.
model PERMA_MEMORY_MODEL your smol role, else omp's smol chain Model that writes summaries: provider/model-id or a role alias.
thinking PERMA_MEMORY_THINKING high (clamped to what the model has) Summary model reasoning: off, minimal, low, medium, high, xhigh, max.
name PERMA_MEMORY_NAME omp The agent's name in the memory prompt.
omp plugin config set omp-perma-memory model github-copilot/claude-haiku-4.5

A setting wins over its env var. For a separate chat per project, set dir in the project's .omp/plugin-overrides.json ({"settings": {"omp-perma-memory": {"dir": "..."}}}).

Commands

  • /perma or /perma status: messages, both views, summaries waiting and running, the summary model, why calls are waiting, the last clipped line.
  • /perma view: writes the view a turn would see now to view.txt in the chat directory.
  • /perma note <text>: logs a note (a memory from before the chat).

How it maps onto omp

UniiChat Here
Log every message as it comes Each new entry of the omp session, in session order, on message_end, turn_end, agent_end
A tool call logged with its result Calls wait for their result entry; calls left without one (a stop) are logged at the run's end
A fresh call per user message context hook: every request is [view] + [this turn's messages]; history before the turn is dropped
settle: a turn waits for the lines before it The turn's first request waits (≤ 25 s; Esc cancels), then freezes the view for the whole turn
Turn: the user's new message: after the view The same head, as the last block of the view message
One system prompt for turns and compactions The memory prompt is appended to omp's system prompt; compactions send it alone
Messages sent while working omp's steering: they join the running turn and are logged as user
No compaction that throws the past away session_before_compact keeps only the current turn, with no summarization call
One cache mark on the view's last whole block before_provider_request (Anthropic models), plus the previous turn's mark after a long turn
Compactor: JOBS 64, ctx order, patient, TRIES 5 Background calls through pi-ai with the session's credentials, flagged as agent-initiated

Message kinds: user (your words, !/$ shell runs), agent (replies), tool (calls), echo (results, @file mentions), work (background job reports, text relayed by other agents), note (/perma note, and Stopped. when a run is cut). Thinking, omp's developer reminders and hidden extension messages are not logged.

Storage

UniiChat's layout, in the chat directory:

  • main/YYYY-MM-DD.jsonl: the messages, one JSON line each (i, kind, text, size, date, images, more on a page a longer text continues), in a file per local day.
  • tree/YYYY-MM-DD.jsonl: the summary tree, one line per node (l, i, text, size).
  • main.index, tree.index: 16 bytes per message or node (offset, day, length), so any line is one read away. They are derived: a start indexes only what was logged past the ends view.json saved, and a lost index is rebuilt from the day files.
  • view.json: both views and how far the logs are indexed.
  • docs/images/: images, by the first 16 hex digits of their SHA-256.
  • lock: held while omp runs (below).

Logs are only ever appended. Writes reach the OS at once and are flushed by group commit (an fsync per file, one flush at a time): a crash of omp loses nothing, a crash of the machine about the last flush. A line a crash cut short is skipped, a message whose last page was lost is not in the chat, and an index entry pointing at data the disk lost is dropped.

The text files can be read, grepped and backed up while omp runs. Don't edit them while it runs.

Choices and their costs

Where this differs from UniiChat's code, or adds what omp needs:

  • A turn waits at most 25 s for the lines of the messages before it: omp gives a hook 30 s, where UniiChat waits as long as it takes. Past that, a message still without a line goes whole in the view (id+1|kind: text, the last ones up to 128 KB, as UniiChat sends its newest messages whole); only one older than those shows (not summarized yet: zoom it). The cache mark stays before the first such line. Cost: a bigger prompt in that turn, and the next turn rewrites the cache from that line.
  • No model, no wait. When no summary model resolves, turns don't wait (UniiChat's held side), and summaries wait with no call. A provider that fails is asked again every 60 s, forever, as UniiChat's patient calls are: any HTTP error, a network error, a missing key. Only a model's own failed answer (a refusal, a content filter, its token cap) or an empty line makes the node its source clipped to 512 bytes, at once.
  • 64 summaries run at once (UniiChat's JOBS). A backlog (a first start on a long chat) sends up to 64 parallel requests on your credentials; a provider's rate limit only delays them.
  • The lock is an exclusive SQLite lock on the file lock (UniiChat holds a unix socket, which is not one on Windows, and Bun has no portable flock). It is the operating system's, so a crashed omp never leaves it behind. A second omp on the same chat runs without memory (the zoom and date tools are off there) and says so.
  • view.json is flushed before it replaces the old one, not after: Windows refuses to replace a file a flush holds open. It is written only when a batch changes a view's lines, so the wait is rare.
  • A view's batch is applied before new summaries start, so a summary's view holds every line built before it (UniiChat starts them first, and a merge could miss its own halves' lines).
  • Unreadable state is rebuilt, not trusted: a lost view.json opens every message as a line and the first batch merges them as due (UniiChat would open the coarsest view: the tree's roots).
  • Cache marks are Anthropic-only (OpenAI-style providers cache prefixes automatically). With at most 4 marks per request, the tools mark is dropped first: the system mark covers the same prefix. When a turn adds more than ~15 blocks (60 lines), the previous turn's mark is placed again, since Anthropic only looks back about 20 blocks for an earlier entry. UniiChat places one.
  • A one-line reminder follows the view ("Each line above summarizes its messages…"). In testing, Claude Haiku 4.5 answered "I don't have that information" instead of zooming without it, with the memory prompt diluted at the end of omp's long system prompt.
  • Prompt adaptations: the agent is name (default omp) and its replies are kind agent, not unii; "the user's instructions at the end of this prompt" becomes "in this prompt" (the memory prompt comes after omp's); the paragraphs about devices, background subagents, imported chats (ai) and zoom("Name") are dropped: omp's own prompt governs tools and subagents. Subagents run without the view.
  • Compaction calls send only the memory prompt, not omp's whole system prompt and tools: the summary model is usually not the turn model, so they could not share the turns' cache anyway.
  • Images are stored as they came: omp already sent them to a model, so no scaled copy is kept.
  • Left out of UniiChat: imports of other chats, subagents' logs, billing, the /tree page and /export, /goal.
  • omp's own errors aren't logged: a failed request is shown and retried by omp; only what the model said is in the chat.

Development

bun install           # or npm install: types for omp 18.8.5, TypeScript, Bun types
bun test              # merge order checked against Taelin's push for t = 0..20,000, logs, views, compactor, migration
npx tsc --noEmit

Without a Bun install, omp's binary is one: BUN_BE_BUN=1 omp test.

Credits

The design and the code this follows are Victor Taelin's: UniiChat (Copyright 2026 Higher Order Company, Apache-2.0). From it come the log and its files, the 512-byte summary tree, the two views and their batches, the merge order (his rollback push, rollback_state_list.js, 2022, carried to any view size), the compactor and its calls, and the system prompt and compaction tasks in src/prompt.ts, adapted as described above.

This is an independent implementation, not affiliated with or endorsed by Victor Taelin or UniiChat.

License

MIT, for this repository's own code. The parts adapted from UniiChat (its prompt text, and the algorithms of Memory.ts and AskAI.ts ported in src/) remain under UniiChat's Apache-2.0 license.

About

Permanent memory OMP plugin based on OptMem

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages