Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
Merge remote-tracking branch 'origin/dev' into feat/bot-memory
leepokai4a205ab2004d
diff --cc docs/design/bot-memory.mdindex 5edf460d,00000000..76e22905mode 100644,000000..100644--- a/docs/design/bot-memory.md+++ b/docs/design/bot-memory.md@@@ -1,938 -1,0 +1,935 @@@+# Bot memory and compaction++Status (2026-10-18): the whole [rollout](#rollout) is built on 2.18.0. That is the cards, the move from+Engram, writes by permission, the checks, dreaming and all three apps (M0); instructions for every harness (M1);+the cache-safe opening with host-run compaction and the handoff (M2); long-form memory files (M3); and the+evaluation, run once (M4). The public mirror (M5) waits only for its repository. How it works today is in+[context and memory](../features/context-and-memory.md); the research behind it is in+[bot memory research](bot-memory-research.md). The numbers are starting values, tuned against the+[evaluation](#evaluation).++Left before release, found 2026-10-18 and put off by the owner for now:+- - **The Android app breaks on merge.** On `dev` (#151–#158) it still calls the memory methods this branch- removes (`memoryDetail`, `reviewMemory`, `exportMemory`, `importMemory`) and has none of the new memory notes,- compaction summaries, handoff cards or `memoryFile` chat lines. Android isn't released, so it doesn't hold the- release, but it needs the same port the other clients got. On merge, add it to the "Not done yet" list in- `docs/plans/android-app.md`.- - **The branch is behind `dev`** (6 commits, all Android); merging conflicts in `docs/guides/development.md`.++- **The Android app's memory screen errors.** It still calls the removed Engram methods and has none of the new++ memory UI. Android isn't released, so it doesn't hold the release; the port is listed in++ [the Android plan](../plans/android-app.md#not-ported-yet).+- **Full e2e on Linux and Windows** hasn't run; only macOS has.+- **Bots inherit the owner's own Claude Code setup** (`~/.claude/CLAUDE.md`, permission mode, claude.ai+ connectors); isolating them waits for the owner's decision ([evaluation](#evaluation)).+- **The move from old memory**, tried on a copy of the owner's data (149, 188 and 3 entries moved, none lost):+ - Old Markdown memory is mostly the bot's own replies ("需要我幫什麼忙嗎?"), and it comes in active up to+ the cap. Only profile, pinned and personal-scope facts should come in active; the rest archived.+ - The old files are deleted once moved, with no backup; entries refused by the checks vanish with them.+ - An empty (0-byte) `engram.db` fails the move on every start, so that bot never finishes moving.++Built differently from the plan below, for now:++- Search is a substring scan, not an FTS5 trigram index. Memory has a few hundred entries; the transcript scan+ took 0.6 s over 180k messages of one bot, so the index waits until a bot's search passes a second.+- No revision history per entry; the dream log and the chat lines carry undo.+- Proposals for a bot that asks first live in their chat card, not in the store, so there is no proposed state.+- Health, religion and politics get no special notice yet; voice transcripts aren't marked, and group rooms+ don't feed dreaming.+- Entries show who wrote them, not a link to the message they were learned from. The bot can follow it:+ `search_memory` returns each entry's source messages, and `search_history` reads back from a message id.+- A memory notice carries the whole memory (at most 1,600 tokens) rather than a delta: a forgotten entry leaves+ no row to diff against, and a whole copy also replaces whatever an earlier notice said.+- The cache's lifetime is learned from turns that come after a pause (most of the input read from cache, or+ not); until a bot has one, Claude on a subscription counts as an hour and everything else as five minutes.+- The host compacts only Claude and Codex ahead of time; other harnesses keep their own timing. Codex's+ compaction line in the chat has no summary, since Codex reports none; its handoff is built from the chat.+- The handoff card appears as soon as a rollover is due, not when the user returns, so it can be edited before+ the message that sends it.+- A memory file changed by no bot's tool call (an editor, another program) is recorded without the checks or a+ chat line: the user owns their computer. Its description is left out of the index when it fails the checks.+- "Drops more than a quarter" is measured as the file getting more than a quarter shorter, so a changed line+ isn't flagged; the diff shows a rewrite either way.++In one line: **memory records the person, the transcript stays in the host, the opening stays frozen until+compaction, and the host decides when to compact.**++## Why redesign++Reading the current implementation turned up these problems.++- **Two writers for one memory.**+ - The agent writes through Engram's MCP tools, and the keeper extracts facts from the same exchanges.+ - Each keeper batch runs the agent twice.+ - User messages are stored three times: transcript, keeper queue, and Engram's captured prompts.+ - Each turn makes three Engram round trips.+- **The mid-session reload doesn't work.**+ - Claude Code records the system prompt on a session's first request and reuses that record until the session+ is compacted. This is on by default since Claude Code 2.1.265 (SDK 0.3.265) and no longer flag-gated since+ 2.1.268. Local transcripts already contain `systemPromptSnapshot` records.+ - When `_meta.systemPrompt` changes, `claude-agent-acp` tears down the query and resumes it, which replays history+ and re-runs SessionStart hooks. The new text still takes effect only at the next compaction.+ - So "memory changed, `session/load` with a new append" restarts the process for nothing.+- **The opening is one compaction late.** The host reacts to `compaction_update` completed by re-rendering and+ loading the new opening. The compaction that just ran already re-recorded the old prompt, so the new one is+ picked up only at the following compaction.+- **Non-Claude harnesses lose the profile.**+ - `<bot-profile>` is sent only in a session's first message (`host/src/agent/bot/turn.rs`).+ - Codex keeps only the last 20k tokens of user messages verbatim when it compacts locally+ (`COMPACT_USER_MESSAGE_MAX_TOKENS`). Remote compaction keeps developer messages only behind a feature flag.+ - `codex-acp` passes developer instructions only on `session/new`, not on load or resume.+ - Codync re-sends the profile in none of these cases.+- **Fork drops the opening.** `session/fork` sends no `_meta`, and the adapter forwards none, so a new thread needs+ an immediate `session/load` (`host/src/agent/bot/session.rs`).+- **Adapter signals are ignored.** Both `claude-agent-acp` and `codex-acp` report:+ - `usage_update{used,size}`;+ - per-prompt `cachedReadTokens` / `cachedWriteTokens`;+ - compaction progress.++ Claude also sends `compact_boundary` token counts and the summary. The host reads only+ `_meta["_claude/rateLimit"]` (`host/src/agent/bot/updates.rs`).+- **A second memory runs unseen.** Claude Code's auto memory and auto-dream run inside bot sessions. Auto memory is+ "loaded into the system prompt at session start", and none of it is visible in Codync.+- **Engram has the wrong shape.** The details are under [Engram](#engram).+ - Engram is built for one coding agent remembering its own work: one database per bot, written only by Engram,+ with Codync reading its schema read-only.+ - That rules out the shared "yours" layer, the write gate, provenance with cascade delete, a dream log with undo,+ and memory writes stamped with `rev` in the same transaction.++## Patterns explored++Two research passes on 2026-10-17 compared the following; a third pass on how open-source agents mix files and a+database, embeddings, and harness instructions is in [bot memory research](bot-memory-research.md).++- **Products:** ChatGPT, Claude, Grok (Grok Bot, Grok Build), Gemini, Codex, Claude Code, Cursor, Amp, Factory,+ OpenClaw, Hermes, Letta, Mem0, Zep/Graphiti.+- **Papers** from 2024–2026.+- **Community threads:** Hacker News, Reddit and GitHub issues.+- **Local sources:**+ - `claude-agent-acp` 0.92.0;+ - Claude Agent SDK 0.3.300, which bundles Claude Code 2.1.300;+ - `codex-acp` on GitHub.++### Where memory lives and who writes it++| Pattern | Seen in | What we found | For Codync |+|---|---|---|---|+| Agent-managed memory through tools | Letta/MemGPT core memory, Engram MCP, Hermes | Agents forget to call the tool, or say "remembered" without calling it. Tool writes bypass any review. Letta shared blocks are last-write-wins. | Not the main writer. The bot's writes follow its permission mode, and every write is visible with undo. |+| Background extractor | Mem0, ChatGPT saved memories, our keeper | One background writer is the consensus. Mem0 went add-only in April 2026 because reconciliation "was where context got destroyed". | Kept as **dreaming**, limited to add and archive. |+| Small profile always in context | ChatGPT saved memories, Claude memory summary, Hermes `MEMORY.md`/`USER.md` | Reliable, because nothing depends on the model deciding to look. Needs a size cap. Hermes' 2,200-character cap caused silent fact loss. | **Adopted** for active memory, capped in tokens. |+| Retrieval on demand | Vector RAG, our former "context" section | A community evaluation found about 60% of failures were the agent never searching. | Only for archived memory and the transcript. |+| Raw transcript search | Letta's filesystem benchmark (grep agent ≈74%) | Beats most memory products. Replacing the transcript with summaries or extracted facts lowers accuracy (LongMemEval). | **Adopted**: `search_history` over the host transcript. |+| Knowledge graph / temporal graph | Zep/Graphiti, A-MEM | Graphiti invalidates old facts instead of deleting them. Benchmark gains are small next to benchmark noise: 6.4% of LoCoMo's answer key is wrong. | Not built. We borrow "supersede, don't delete". |+| File-based memory | CLAUDE.md, Claude Code auto memory, Codex memories, OpenClaw `MEMORY.md` | Transparent and editable, but no transactions and no sync to three clients. | SQLite, made fully visible in the UI. Harness file memory stays for project bots only. |+| Sleep-time consolidation ("dreaming") | ChatGPT dreaming, Claude Code auto-dream, OpenClaw, Letta sleep-time, Grok Build `/dream` | Useful, and every product adds guards. OpenClaw rejects a rewrite that removes more than 0.25 of entries and keeps a pre-image. Hermes removed its `replace` action because it wiped other facts, and #5563 traced lost memory to corruption and the cap. Claude Code auto-dream keeps "no log of what was created, modified, or removed" (#38493). | Adopted, with the guards below. |+| External memory service | Engram, Mem0 cloud, Supermemory, Honcho | A separate process owns the writes and has its own failure modes. | Dropped. |++### Scoping across bots++| Product | Scope |+|---|---|+| Grok Bot | Per bot: "Memory and Routines belong to the Bot … context remains with the role" |+| Claude Projects | Per project, with a per-project "Use account memory" toggle |+| ChatGPT Projects | "Project-only memory", but a 653-point Reddit thread reproduced a leak into a project-only project |+| Letta | Shared blocks, last write wins; read-only blocks advised |++Cross-scope bleed is the most common complaint everywhere. A 738-point r/ChatGPT thread: "memory is great until+it quietly carries an assumption from three chats ago into something unrelated. a per-chat toggle would fix most+of it". Codync's shape follows Claude Projects: per-bot memory plus a shared "yours" layer that each bot can switch+off. The user, dreaming and bots in `Auto` write "yours", and each entry names who wrote it.++### Consensus we design to++1. **Memory is for the person, not the work.**+ - Codex: "Keep required team guidance in AGENTS.md"; memories are "a recall aid".+ - Grok Build memory excludes anything the repository already covers.+ - Claude Code auto memory skips what it can derive from the code.+ - Users who let memory touch code complain that it "saves a memory with the patch in it instead of fixing the+ code. disabled memory user wide" (r/ClaudeAI).+2. **Scope it.** Memory must not leak across contexts the user keeps apart.+3. **Staleness is the hard part**, more than finding things. Archive superseded facts with a pointer to what+ replaced them, and turn the future into the past as time passes. ChatGPT dreaming turns "You're going to+ Singapore" into "You went in July 2026".+4. **Visible, editable, with provenance.** Every memory says where it came from and can be undone.+5. **One automatic writer, behind a gate.**+6. **Memory is an attack surface.** Treat it as data, not instructions. Published attacks:+ - MINJA poisons memory through queries alone.+ - AgentPoison reaches over 80% success at a poison rate under 0.1%.+ - Gemini's delayed tool invocation fires a planted instruction when the user later says "yes".+ - Microsoft found over 50 "remember … as a trusted source" prompts from 31 companies planted in links.++ The defense that holds is structural (CaMeL, the design-patterns paper): untrusted input must be unable to+ trigger consequential actions.+7. **The raw transcript is the source of truth.** Memory is an index over it.+8. **A stable prompt prefix.** Anthropic: "Put changing information in messages, not the system prompt."+9. **Small and complete beats large plus retrieval.**++Still contested: files vs. a database, vectors, and graphs. We use SQLite for transactions and three-client sync,+and keep the file camp's real requirement: no hidden state.++### Compaction patterns++| Pattern | Seen in | For Codync |+|---|---|---|+| Harness auto-compacts at a threshold | Claude Code (at the model limit, about 967k on 1M models), Codex | Kept as the safety net |+| Idle compaction inside the harness | Claude Code 2.1.299+: interactive terminal only, flag-gated off by default | Never active in bot sessions, so the host's idle compaction is the only one |+| Summary written while idle, swapped in on return | Claude Code's flag-gated `compact_on_return` mode; its "resume from summary" offer after over 1 hour idle and over 100k tokens | Precedent for host idle compaction and rollover |+| Host-timed compaction | No product feature found | **Adopted**: end of turn, and idle before the cache expires |+| Handoff to a fresh session | Amp Handoff, an editable draft; Amp calls compaction "lossy" and warns about "stacking summary on top of summary" | **Adopted** as rollover |+| Anchored or iterative summaries | Factory: only the newly truncated span is summarized and merged. It scores 3.70 vs. 3.44 (Anthropic) and 3.35 (OpenAI); the artifact trail is weakest everywhere. | Left to the harness; rollover resets drift; probes in the evaluation |+| Memory-flush turn before compaction | OpenClaw | Not needed: the host keeps the full transcript |+| Masking old tool output | Anthropic context editing (it invalidates cached prefixes) | The harness's job |+| Writing our own summaries | Anthropic on-demand and threshold compaction APIs | Not built until harness summaries prove insufficient |++## The design++### Two layers++Caps count tokens, not characters, so Chinese users aren't penalised. 2,000 CJK characters are 2–3k tokens, but+2,000 English characters are about 500. The estimate is CJK-aware: one token per CJK character, one per four Latin+characters.++| Layer | Holds | Cap (initial) | Default | Scope |+|---|---|---|---|---|+| **Yours** | Name, time zone, language, important people, standing preferences | ≤ 400 tokens | On for personal bots, off for project bots | Shared by all bots |+| **This bot** | How to work with you, promises, ongoing commitments | ≤ 1,200 tokens | Always on | One bot; wins over "yours" when they conflict |++Active total: ≤ 1,600 tokens per opening. For comparison:++- Hermes: about 800 + 500 tokens;+- the Claude Code `MEMORY.md` index: 200 lines or 25 KB;+- Letta blocks: 5,000 characters by default.++Placement:++- **Active** memory is placed in full in the session opening.+- **Archived** memory is out of the prompt and searchable with FTS5 trigram, which also handles Chinese.+- Past a cap, dreaming moves detail into a long-form file or archives entries.+- Project knowledge stays in the harness's files (`AGENTS.md`, `CLAUDE.md`).++### Long-form memory++Cards hold what a reply goes wrong without. Detail that matters only when its topic comes up lives in Markdown+files the bot reads and edits with its own tools: every system studied keeps a small always-loaded layer and a+larger one read on demand ([research](bot-memory-research.md#lessons-across-systems)).++| | Cards | Long-form files |+|---|---|---|+| Holds | Name, time zone, allergies, "don't …" | One topic's detail: people, health, plans, trips |+| Home | `memory_entries` | `shared-memory/*.md` and `bots/<id>/bot-memory/*.md`; versions in `memory_file_versions` |+| Cap | 400 + 1,200 tokens; 150 per entry | 20 files per folder; 2,000 tokens per file |+| In the opening | In full | An index: path, description, size |+| The bot reads | — | With its own file tools, or `read_memory` |+| The bot writes | Memory tools | With its own file tools, or `edit_memory` |+| Checked | Before the write | Before the write through `edit_memory`; at turn end for its own edits |++**What lives where, and why.** The split isn't raw versus summary. The transcript (every word, the source of truth)+and the cards (the fewest facts) are both in `codync.db`; the files sit between them, detail organized by topic.+They aren't conversation summaries: Codync writes none of its own, and a harness's compaction summary is kept as a+transcript entry.++- **Cards and the transcript need more than one file's atomicity.** A rename replaces one file atomically, but a+ card write commits the card, `rev` and the chat's "Remembered" line together, and the transcript has concurrent+ writers (the user, a streaming reply, routines, dreaming) whose read-modify-write a rename doesn't serialize.+ Files would also need `fsync` on the file and its folder, a retry when Windows refuses to rename a file another+ process holds open, and a whole-file rewrite for every streamed update. SQLite is built from those same file+ system parts, already assembled. Search speed isn't the reason: the transcript search is a scan.+- **Claude Code's transcript shows when files are enough.** It keeps one JSONL file per session+ (`~/.claude/projects/<project>/<session>.jsonl`): one process writes it, lines are only appended and never+ changed, nothing else commits with them, no other client syncs from it, and a torn last line after a crash is+ skipped. Codync's transcript has none of those properties.+- **A card is one row**, so it can point at its source message, be undone, pinned or superseded on its own, and be+ checked before it's written. A file is prose the bot changes a sentence at a time with Edit.+- **Most card operations aren't appends.** Revising, archiving with a pointer to the replacement, pinning,+ forgetting, the daily time review, the cascade when a message is deleted and making room in a full layer each+ change one entry in place; in a file each is a rewrite.+- **Cards are reached only through fixed memory tools, which keeps their provenance out of a prompt injection's+ reach.** `remember` takes the text and the layer; `revise_memory` and `archive_memory` take an id and refuse the+ user's own entries. The host fills in the author, the writing bot, the source messages and the time, and the+ harness's file tools edit text files, which cards aren't. A bot tricked by a web page can therefore write at most+ a card under its own name, from that turn, shown as a "Remembered" line with undo. It can't mark a card as the+ user's, cite a message that never said it, or rewrite the user's entries. In a Markdown file that provenance+ would be text the bot edits: `- authorized automatic payments <!-- author: you | source: #3051 -->` would show+ as the user's own entry, and dreaming, which never changes the user's words, couldn't remove it. Grok Bot, files+ only, keeps provenance in separate hash-named files for this reason; OpenClaw keeps it in SQLite because the+ model "cannot write through prose". This holds against text that steers the bot, not against a bot running+ `sqlite3` from its shell on purpose: it isn't a sandbox.+- **A file is its note's only live copy, not a pointer into the database.** The bot reads it from disk (Read or+ `read_memory`); its index line in the opening comes from its frontmatter. `memory_file_versions` is history taken+ by the scan, for undo and authorship, and can trail the file until the turn ends. Cards reach the bot through the+ opening, from `codync.db`.++**Paths and format.**++- `<data>/shared-memory/` belongs to the shared layer; `<data>/bots/<id>/bot-memory/` to one bot. Not `memory/`:+ the move from the old memory deletes `bots/<id>/memory` on every start.+- File names are lowercase ASCII slugs (`[a-z0-9-]+.md`), one level deep. The title inside can be any language.+ Unicode and case variants of a name would otherwise become duplicate notes (Basic Memory #1275, #1281).+- Every file starts with frontmatter whose `description:` says when to read it. It becomes the file's index line.+- Only regular `.md` files count. Symlinks, hidden files and subfolders are ignored, so a link can't make the host+ read, journal or restore another file.+- An index or a file over its cap is marked in the opening and the apps, never cut.++**The scan.** At the end of every turn, before an opening is rendered and when an app asks, the host scans the+folders the bot can see:++1. Unchanged mtime and size skip a file. One modified in the last 2 s waits for the next scan.+2. A SHA-256 different from the recorded version is a change. A folder that went missing is not "every file+ deleted".+3. The change runs the same checks as every other write (hidden characters, prompt links, planted instructions,+ secrets), plus the caps and the description.+4. It becomes a new version holding the full content. Its author is the bot whose tool call touched that path+ since the last version, otherwise "this computer".+5. A change that fails a check is restored to the previous version and the chat says why. A change that drops more+ than a quarter of the file is kept, flagged in the chat, and can be undone.++**Host writes** (the apps, `edit_memory`, dreaming) are compare-and-swap: re-read the hash, write a temporary file+in the same folder, rename it over the note. A note that changed meanwhile isn't overwritten; the write fails, a+scan records the other change, and the write is retried on top of it. The host never reformats a file+(Basic Memory's own rewrites duplicated frontmatter, #1171).++**Permission.** The bot's own file edits go through the harness's permission requests, which an `Ask` bot shows as+cards and an `Auto` bot approves. `edit_memory` follows `Permission` like `remember`.++**Dreaming** may append to a file, or move detail from a full card layer into one, under the same evidence rules.+It never rewrites a file.++**Scope and lifecycle.** A bot that doesn't use the shared layer sees neither `shared-memory/` in its index nor the+folder itself. Deleting a bot deletes its folder and versions, and "Forget everything" deletes a layer's files+with their versions. Deleting one file through the apps or the bot keeps it as a version that can be restored.++**Version history (open).** Every version keeps its full content and nothing is pruned yet: about 6 KB per version at+the file cap, so a note edited a few times a week adds about 1 MB a year. Two ways to bound it:++- keep every version for 30 days and the last one of each day after that;+- keep the history in a git repository outside the folders (`<data>/memory-history.git`, used with `--git-dir` and+ `--work-tree`, committed only by the host at the scan), which stores deltas and gives `log`, `diff` and `blame`.+ Hosts without git embed it (`gix`). Removing content from git history takes a rewrite and `gc`, so with git+ "Forget" takes a note out of current memory and leaves its history, and bots get no tool that reads that history.++### Writers and the gate++- **The user, in the UI**: writes directly.+- **The bot**, through its memory tool, follows the bot's permission mode (`Permission`):+ - `Auto`, the default for new bots: the write goes straight in, to this bot's layer or to "yours", in any turn.+ The lane where it happened shows a "Remembered" line with undo, and the memory screen lists the entry with+ the bot that wrote it.+ - `Ask`: the write becomes a confirm card in all three clients, and accepting it is a UI write. An explicit+ "remember …" the user typed (not pasted) is written directly in both modes.+- **Dreaming**: proposes. It is the only background writer, and it also records an explicit "remember …" the user+ typed when the bot didn't call its tool. It may merge or archive bot-written entries, never the user's own.++These checks are deterministic code in the core, not another model's judgment. Dreaming proposals pass all of+them. Bot writes, in either mode, pass the last two (instruction-like content and sensitive data) and the cap.++- **Evidence must be user-authored.** Each item quotes the user verbatim and cites at least one message id.+ - The quote must appear in a user-authored span.+ - Code fences, blockquotes, attachments, forwarded text and spans the composer tagged as pasted don't count.+ The iOS, desktop and TUI composers mark pasted spans.+- **Minimum content.** A quote of three content tokens or fewer, or one that is only an acknowledgement (好, yes, ok,+ sure), can't carry a memory. This stops the delayed-trigger attack and "shall I remember X?" loops.+- **Instruction-like content is rejected:**+ - "remember / 記住" imperatives addressed to the assistant that didn't come from the user's typing;+ - a fixed list of planted phrases (`ignore previous`, `system prompt`, `you are now`, `trusted source`, 忽略之前,+ 系統提示, 可信來源, …);+ - invisible Unicode;+ - URLs with prompt-carrying parameters (`q`, `prompt`, `query`, `instructions`).++ The list catches known attack wording only. A planted fact in plain words ("the user authorized automatic+ payments") passes; what bounds it is provenance the bot can't set, the "Remembered" line with undo, `Ask`'s+ confirm card and dreaming's review.+- **Sensitive data.**+ - Passwords, government ID numbers and account numbers are never stored, even when asked.+ - Health, religion and politics are stored only on explicit request, with a visible notice.++Source policy:++| Source | Can create memory |+|---|---|+| UI edit | Directly |+| User text in the main chat or a thread | Yes, through the gate |+| User text in a group room | Only for the bot(s) addressed, tagged with the room id |+| Voice transcript (`source: voice`) | Only after UI confirmation or a second occurrence. Audio-model attacks such as AudioHijack reach 79–96%. |+| Bot-to-bot requests | Never. They also never read another bot's private layer. |+| Bot output, routines, webhooks, files, web pages | Never |++The table governs dreaming. In `Auto`, the bot decides what it writes, in any turn and from anything it read,+including turns a routine, a webhook or another bot started. That is the risk `Auto` accepts, bounded by the+visible line with undo, the hard checks and dreaming's later review. A bot that shouldn't see what others write+can switch "yours" off.++### Dreaming++**Schedule.**++- It runs after five idle minutes or eight queued user messages.+- It also runs before any host-initiated compaction or rollover.+- It is skipped while subscription usage is above 75% of the window. Codex keeps the same 25% headroom with+ `min_rate_limit_remaining_percent`.++**How it runs.**++- It uses a fresh, tool-free context on the bot's cheapest model. The keeper already does this: `tools: []`, Haiku.+- It reads the transcript from a bookmark forward.+- Untrusted and system-provenance spans are stripped before the proposal prompt (OpenClaw does the same).+- It reads the current entries, bot-written ones included, and doesn't add what is already there.++**Pipeline.**++1. Proposal.+2. Audit.+3. The host re-checks the result deterministically.+4. One transaction writes memories, revisions, the dream log and `rev`.++The transaction aborts if the bot's memory `rev` changed since the dream's snapshot, so a UI edit made during the+run is never overwritten (OpenClaw uses optimistic concurrency the same way).++**Rules:**++- **Your words are fixed.** Entries the user wrote, or explicitly asked for, can never be changed by dreaming.+- **Add and archive only.** Dreaming never rewrites or deletes. Archiving names what superseded the entry.+ Deletion happens only when the user presses Forget.+- **Limits.** At most 10 operations per run. A batch that would archive more than ¼ of active entries is rejected+ whole (OpenClaw's default is also 0.25).+- **Tombstones.** A forgotten entry leaves only a content hash, so dreaming can't grow it back. Its revisions are+ deleted too.+- **Cascade.** Deleting a message deletes memories learned only from it. ChatGPT ("Deleting a chat alone does not+ necessarily delete a separate saved memory") and Claude ("related memory entries generated from it won't be+ removed") don't do this.+- **Time review, daily.** Future tense turns into the past once the date passes. Relative dates become absolute at+ write time.+- **Dream log.** Every run's changes are visible and can be undone in one tap.+- **Migrated entries.** Entries imported from Engram or Markdown change only on contrary evidence.++### Frozen opening++The opening, in order:++1. harness tools and preset;+2. identity and rules;+3. yours;+4. this bot.++It stays byte-identical until compaction or a new session.++- **Claude transport.** Send the object form, which the adapter spreads into the SDK preset:+ `_meta: {"systemPrompt": {"append": …, "excludeDynamicSections": true}}`.+ - Not the ACP spec `systemPrompt` field yet: for Claude the adapter rebuilds it as preset plus append and drops+ the other options.+ - `excludeDynamicSections` moves the working directory, git status and similar per-session context into the+ first user message. The opening is then identical across a bot's main chat, threads and routines, and a new+ session reads the cache.+- **Change the opening only at compaction or rollover.** Every change restarts the adapter's query and replays+ history. Resume has had regressions, such as 2.1.288 dropping files a compaction had just restored.+ - The SDK has undocumented mid-session invalidation hooks (`liveAppendSections`,+ `CLAUDE_CODE_HOST_PROMPT_SUPERSEDES_RECORD`).+ - They are unstable and any re-render invalidates the system-prompt cache layer, so the design doesn't depend on+ them.+- **Deltas.** Changes made elsewhere reach the bot as one `<system-reminder>`-style block prefixed to its next+ message. That covers UI edits and what other threads or bots learned.+ - Nothing is sent for what this session learned itself, because the bot already heard it.+- **Ledger.** It records two numbers per session: the memory revision the opening contains, and the revision deltas+ have delivered up to.+- **The handoff summary goes in the first user message**, not the opening, because it differs per session.+- **Fork.** Re-send the parent's `_meta.systemPrompt` on `session/fork`.+- **Settings isolation.** Consider `settingSources: []` or `["project"]`. The adapter default+ `["user","project","local"]` loads the user's own `~/.claude/CLAUDE.md` and settings into every bot.++### Instructions in every harness++Codync runs 27 harnesses. The opening, with the bot's identity and memory, reaches each through the best channel+it offers (`Instructions` in `agent/bot`):++1. **Claude: `_meta.systemPrompt`**, as above. claude-agent-acp 0.92 also advertises ACP's `systemPrompt`, but it+ rebuilds that field without the object options (`excludeDynamicSections`), so Claude stays on `_meta`.+2. **ACP `systemPrompt`** ([Client-Provided System Prompt](https://github.com/agentclientprotocol/agent-client-protocol/blob/main/docs/rfds/client-system-prompt.mdx),+ unstable): when an agent advertises `sessionCapabilities.systemPrompt`, the opening goes as+ `{"mode": "append", "content": [text]}` on `session/new`, `session/load` (the session's current snapshot) and+ `session/fork` (the main session's). The agent keeps it at system level, across compaction.+3. **Every other agent: the first message.** A `<bot-profile>` block precedes the first prompt of a new session.+ After a compaction the next prompt carries a fresh one that says it replaces any earlier profile, so the agent+ never holds two versions that disagree. The compaction is the agent's `compaction_update`, or, for an agent+ that never sent one, its `usage_update.used` falling below half of a previous value of at least 20k.++Measured 2026-10-18 at `initialize`:++| Agent | `systemPrompt` | `additionalDirectories` |+|---|---|---|+| claude-agent-acp 0.92.0 | Yes | Yes |+| codex-acp 2.2.2 | No | Yes |+| OpenCode 1.19 | No | No |+| Copilot CLI | No | No |++codex-acp reports compactions (`compaction_update`). Codex keeps the user's newest ~20k tokens of messages+through a compaction, so a first-message profile survives+short sessions and is the first thing dropped in long ones. In a real run past that budget (two 15k-token+messages, then `/compact`), Codex still knew the bot's name and the user's allergy afterwards, from its summary;+the re-sent profile makes that independent of what the summary keeps. codex-acp also reads+`_meta.jetbrains.air.customInstructions` on `session/new` as Codex developer instructions. It isn't used: it is one+vendor's extension, and it isn't re-sent on `session/load`.++Verified on a real host (2026-10-18): a Codex bot got its profile again on the first message after `/compact`+and still knew its name and the user's allergy; a Copilot bot reported no `store_memory` tool; a Claude bot+answered from its memory as before.++**File access.** The memory folders a bot can see go as `additionalDirectories` on every session request, when+the agent advertises the capability (M3). Agents that can't reach them read and write through `read_memory` and+`edit_memory`.++**The harness's own memory.** For a bot in its own workspace, and for every background job, Codync turns each+harness's own memory off where it can, so the bot has one memory and it is visible (`agent/own_memory.rs`,+surveyed 2026-10-18):++| Harness | Its own memory | What Codync does |+|---|---|---|+| Claude Code | Auto memory, auto-dream | `autoMemoryEnabled: false`, `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1`, `autoDreamEnabled: false` |+| Copilot CLI | Copilot Memory, on for individual plans | `--excluded-tools=store_memory,vote_memory` |+| Qwen Code | Auto memory and its own dreaming, on | `.qwen/settings.json` in the workspace: `memory.enableManagedAutoMemory` and `enableManagedAutoDream` false |+| CodeBuddy | Auto memory | `CODEBUDDY_DISABLE_AUTO_MEMORY=1` |+| Codex, Goose, Grok, oh-my-pi, Qoder, Cortex | Off unless the user turns it on | Nothing |+| Gemini CLI | Its system prompt has the model edit `~/.gemini/GEMINI.md` | Nothing: no switch short of replacing its system prompt or its home folder |+| Kilo Code | Memory tools, on per project | Nothing: the only per-process switch replaces the whole config |+| Kiro | Memory with a global setting | Nothing: no per-workspace key |+| OpenCode, Cursor, Kimi, Amp, Cline, Droid, Devin, others | None found | Nothing |++### Compaction++The harness writes the summary, because it knows the work: files read, todos, tool results. The host decides+**when**, because it knows how full the context is, whether the user is present and whether the cache is warm.++Cache economics (Anthropic):++- a cache read costs 0.1× input, or less on newer models (0.05× on Opus and Sonnet 5.5);+- a 5-minute cache write costs 1.25×;+- a 1-hour cache write costs 2×.++Compacting an idle session before its cache expires beats a cold re-read once the context passes roughly 70–90k+tokens at 0.1× reads. Recompute this per model.++The 1-hour TTL applies to SDK turns only "on a Claude subscription within your plan's included usage". On+extra-usage credits or an API key it drops to 5 minutes. The host reads the TTL actually in use (the SDK's+`usage.cache_creation` separates 5-minute and 1-hour writes), or pins `promptCacheTtl: "1h"` for main lanes, which+doubles the write cost on API billing.++| Trigger | When | Why |+|---|---|---|+| **End of turn** | `used ≥ min(0.75 × size, 200k)` when a turn ends, leaving room for the summary (about 20k tokens) | The cache is hot, so reading the history costs ≈1/10. Nothing stalls mid-task. |+| **Idle** | 1-hour TTL: at TTL − 5 min when `used ≥ 100k`, main lane only. 5-minute TTL: no idle compaction. | Cheaper than a cold read on return. The threshold sits above break-even because compaction loses detail. |+| **Rollover** | Any of: (1) returning with a cold cache and `used ≥ 100k`; (2) away ≥ 8 hours with ≥ 3 compactions; (3) the loop guard fires | Summaries of summaries drift. A new session starts with a handoff. |+| **Safety net** | A single turn fills the window | The harness's own auto-compaction |++The `idleCompaction` setting needs no change. The harness never idle-compacts in SDK/ACP sessions, and setting it+to true "does not turn idle compaction on".++**Loop guard.** It allows at most 3 host-initiated compactions per lane per 24 hours. If post-compaction usage is+≥ 60% of the trigger, or two compactions happen within 5 turns, the host rolls over instead.++- Claude Code added a 3-attempt circuit breaker in 2.1.76 and thrash detection in 2.1.89, and still fixed+ "conversations being compacted over and over" in 2.1.301.+- One issue reported 211 compactions in a single session.++Threads, group rooms and routines are never compacted early. Most are not revisited, so the cost isn't spent ahead+of time. When the main chat is nearly full, a new thread starts from a handoff instead of a fork.++**Before a host-initiated compaction:**++1. dream;+2. render a new opening with the latest memory;+3. load it into the session;+4. compact with a keep-list.++This order puts the new opening into the very compaction that runs. Anthropic's docs say "the first compaction+switches to the current prompt".++How the keep-list is passed:++- **Claude:** `/compact <instructions>`, which the SDK turns into `custom_instructions`.+- **Codex:** `/compact` ignores trailing text, so the keep-list goes in as `compact_prompt` through `CODEX_CONFIG`.++The keep-list:++- **Verbatim:** the last user request, and every "don't / 不要".+- **Exact identifiers:** paths, URLs and ids (OpenClaw keeps "exact opaque identifiers").+- **Kept:** decisions with reasons, pending tasks with the next step, who said what in rooms, and the thread intro.+- **Left out:** identity and memory, because the host re-injects them.++The keep-list also lives in the opening, so harness-initiated compactions see it.++**After any compaction.** The signal is `compaction_update` completed, Claude's `compact_boundary`+`pre_tokens`/`post_tokens`, or a sudden drop in `usage_update.used` for harnesses that don't notify. Then:++1. Reset the ledger's delivered number to the opening's, and send one merged delta.+2. Re-send `<bot-profile>` to non-Claude harnesses. Do the same after every resume.+3. Re-send the thread intro inside a thread.+4. Store the summary as a transcript entry and show an "Earlier conversation summarized" card.+ - Codex's `compaction_update` carries no summary. For Codex the host builds the card from its own transcript:+ the boundary plus the latest turns.++**Rollover handoff.** It contains:++- the last compaction summary;+- the last 3–5 user turns verbatim;+- the open plan;+- a bookmark: the id of the old session's last message. The new session reads back from it with+ `search_history`'s `from` instead of guessing words, and pages on with the `next` each result page returns.++The user can edit it as a draft before it is sent (Amp's handoff works this way).++### Claude Code's own memory++| Bot | Auto memory | Auto-dream | Why |+|---|---|---|---|+| Personal (workspace Codync created) | Off: `autoMemoryEnabled: false` + `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` | Off: `autoDreamEnabled: false` | Only one memory, fully visible in Codync |+| Project (points at a real repo) | On | Off | It is the project's working memory. |++For project bots:++- The auto-memory directory is shared with the user's own Claude Code sessions in the terminal.+- Its `user`/`feedback` notes overlap Codync's person memory.+- Codync shows the project's `MEMORY.md` read-only, so it isn't unseen.+- The opening states the split: people in Codync memory, the project in harness memory and `CLAUDE.md`.++The adapter passes `claudeCode.options.settings` and `.env` through untouched, so these settings reach the SDK.++### Storage++Host SQLite (`codync.db`), one transaction per change, every change stamped with `rev`. The `codync-mem` tables:++- `memory_entries`: the cards, with layer, active/archived, author and writing bot, room, pin, dates and evidence+ message ids;+- `memory_tombstones`: hashes of forgotten text;+- `memory_dreams` and `memory_dream_changes`: the dream log;+- `memory_files` and `memory_file_versions` (M3): each long-form file's path, layer, hash, size, mtime,+ description and tokens, and every version's full content, author and cause;+- `memory_meta`: the schema version.++The transcript is the host's own `entries` table: it is the chat itself, which the apps sync by `rev` and which+changes in place while a reply streams. Search is a substring scan. When one bot's search passes a second, its+text moves to a plain column and an FTS5 trigram index with a CJK bigram column takes over: measured over 180k+messages, the scan took 0.50 s, ripgrep over the same text 0.013 s, and the trigram index 0.002 s after a 26 s+build.++### UI (all three clients)++- **Two sections**, "About you" and the bot's own. Each entry shows where it was learned, with a link to the+ message.+- **A per-bot switch** for "yours".+- **Bot writes:** a "Remembered" line with undo in the chat (`Auto`), or a confirm card (`Ask`). Voice-only memories+ also get a confirm card.+- **The dream log** with undo.+- **Entry actions:** edit, pin, forget, and forget everything.+- **For project bots**, the project `MEMORY.md`, read-only.+- **Long-form memory** under each layer's cards: the files with name, description, size and date, an over-cap+ mark, and a detail view to read, edit, and restore any version. The desktop app can open a file in the user's+ editor.+- **In the chat**, an "Updated people.md" line with the diff and undo, and why a blocked change was restored.+- **In the chat**, a summary card after compaction, and an editable handoff draft at rollover.++### Deliberately not built++Each of these has a trigger for adding it later.++| Not built | Add it when |+|---|---|+| Vectors | Keyword search and the bot's own rephrasing miss real cases; then a local model only, and a model change rebuilds the index |+| Knowledge graph | — |+| Project or team tiers | — |+| Multi-computer sync | — |+| Our own compaction summaries | Harness summaries prove insufficient |+| Per-reply memory citations | — |+| Engram | — |++## Engram++Engram fits its own goal: one coding agent's memory of its own work. The mismatch is shape, not quality.++| Engram | Codync needs |+|---|---|+| One database per bot; a `personal` scope stays inside it | A "yours" layer shared by all bots |+| Engram owns every write; Codync reads the pinned schema read-only | The gate, provenance with cascade delete, revisions, tombstones and dream undo, all inside Codync |+| The agent writes through Engram's tools, unseen and unlabeled | Bot writes follow its permission mode, name the bot, and show with undo |+| A separate process per bot; downloaded on first use; a lost acknowledgement means a write can't be retried safely | Memory that is as reliable as the host |+| Separate from `rev` | Memory and `rev` written in one transaction |++Everything Engram provides that we use, FTS5 search and a few tables, is a few SQLite tables in the host.+`host/src/chat/memory/engram/` (install, process, migration, backup, clear) disappears.++## Packaging++The memory system is built as a self-contained crate, `codync-mem`, so other ACP clients can use it later.++**A core that only decides (sans-IO).**++- The core has no processes, network, model calls or threads. Events and data go in; changes and commands come+ out.+- It contains:+ - the store;+ - the gate;+ - the dreaming rules;+ - the opening, delta, keep-list and handoff renderers;+ - the compaction-timing state machine with its loop guard;+ - the mapping from commands to ACP payloads (`_meta.systemPrompt` for Claude, first message for others,+ `compact_prompt` for Codex).+- It uses the **caller's SQLite connection**, keeps its own tables and migration version, and writes in the+ caller's transaction. Memory and `rev` therefore commit together.+- **Model work goes back to the driver.** The core returns a job (prompt plus answer format). The driver runs it+ on the user's own harness and never calls provider APIs. The core validates the answer deterministically before+ writing: user-authored verbatim evidence, minimum content, the ¼ guard, the operation limit, the format, and the+ `rev` precondition.++**Drivers.**++- **The Codync host** embeds the core. It is the full product: three-client UI, transcript in the host, and a gate+ that sees only what the user typed.+- **An ACP proxy (later)** lets any ACP client use the core without changes: `codync-mem acp -- <agent command>`.+ - It can inject deltas and observe `usage_update` and `compaction_update`.+ - It can't set the opening. The [proxy chains RFD](https://agentclientprotocol.com/rfds/proxy-chains) (Draft)+ says proxies "cannot directly modify an agent's system prompt".+ - That waits for the [Client-Provided System Prompt RFD](https://github.com/agentclientprotocol/agent-client-protocol/blob/main/docs/rfds/client-system-prompt.mdx),+ which adds `systemPrompt {mode, content}` to new, load, resume and fork. It is in the schema behind an+ unstable feature (PR #2361), and claude-agent-acp 0.92 advertises it.+ - It can't separate what the user typed from what the client injected, so its gate is weaker.+ - It has no UI; a CLI covers review and undo.+ - Dreaming and compaction run between turns on the user's quota.++ACP status as of 2026-10:++- Completed: Session Usage, and Session Compaction (2026-10-06).+- Draft: End-Turn Token Usage, Session Fork, Client-Provided System Prompt, Proxy Chains.++**Repository.**++- The crate lives at `host/crates/memory`, as a member of a `[workspace]` added to `host/Cargo.toml`.+- The build output stays in `host/target`, so `npm run dev` and packaging are unaffected.+- CI runs `cargo clippy --workspace`.+- **Codync is the source of truth.** Core and host will change together for months, since memory and `rev`+ commit in one transaction, so the crate is developed only here. No git submodule.+- **A read-only public mirror, `leepokai/codync-mem`,** gives outside developers a repository of their own.+ - On every push to `main` that touches `host/crates/memory`, CI runs+ `git subtree split --prefix=host/crates/memory` and pushes the result to the mirror's `main`.+ - The split is deterministic, so the push always fast-forwards as long as nobody commits to the mirror.+ - Issues are filed on the mirror. PRs go to Codync's `dev`: a bot answers a PR opened on the mirror with that+ pointer and closes it.+- **The crate builds on its own**, because the mirror is a plain copy of its folder:+ - its `Cargo.toml` inherits nothing from the workspace (lints, edition and version are written out);+ - its CI lives in `host/crates/memory/.github/workflows/`. GitHub reads only the root `.github`, so the CI is+ inert in Codync and runs once the folder is the mirror's root;+ - it re-exports `rusqlite` and documents the supported version. Callers pass their own connection, and one build+ can't link two `rusqlite` versions to `sqlite3`;+ - it has its own README and LICENSE (Apache-2.0).+- The crate has its own 0.x versions, separate from Codync's.+- Open the mirror when rollout step 1 ships (the host calls the crate), marked 0.x with an unstable API. Publish+ 0.1 to crates.io, with the proxy, only after Codync runs on it.+- **Flip later.** When outside users send PRs, the API stops changing with host changes for a few months, or the+ proxy gains users:+ - stop the sync and develop in the mirror;+ - switch Codync to the crates.io release and delete `host/crates/memory`.++ The mirror already holds the history, so nothing moves.++## Verification status++What the research answered:++1. **Does compaction pick up the latest loaded opening? Yes.**+ - Docs: "The new text takes effect after that compaction, or in a new session."+ - In the SDK binary, the recorded prompt is a hidden `prompt_snapshot` attachment. After a full compaction the+ message list is rebuilt without it, so the next request renders from the current options. This part is+ inferred: no explicit delete was found.+ - Resume reads the record and doesn't re-record.+ - Hence: render, load, then compact.+2. **Can the settings be set through ACP? Yes.**+ - `autoMemoryEnabled`, `autoDreamEnabled` and `idleCompaction` go through `claudeCode.options.settings`, which+ the adapter passes on untouched.+ - `excludeDynamicSections` and `snapshot` go on the `_meta.systemPrompt` object.+3. **What does Codex report?**+ - `codex-acp` reports `usage_update{used,size}` (from `thread/tokenUsage/updated`) and per-turn cached tokens.+ - It sends `compaction_update` in_progress/completed when the client declares `session.compaction`, which+ Codync does. The update carries no summary and no token counts.+ - Its `/compact` takes no instructions.+4. **Is recording on for Codync's sessions? Yes.**+ - Default-on since Claude Code 2.1.265; the feature-flag dependency ended in 2.1.268.+ - In 2.1.300 only `systemPromptSnapshot: false` or `CLAUDE_CODE_SIMPLE` turn it off.+ - Installed versions: Claude Code 2.1.301 and adapter 0.92.0 (SDK 0.3.300).++Still unknown:++- **Partial compaction:** how "Summarize from here" treats the recorded prompt.+- **2.1.301:** the installed binary wasn't searched, only the 2.1.300 binary bundled in the SDK.+- **Codex's auto-compact threshold:** about 90% of the window, from a secondary source only.++The real flow, measured on a real host with Claude (Opus, 1M window; 2026-10-18):++- **Cache:** after the first turn, a plain turn read about 97k tokens from cache and wrote about 250.+- **Memory change mid-session:** a card saved between turns reached the bot in the next message. That turn+ wrote 264 tokens to cache, so there was no reload.+- **Thread:** a thread forked from that chat knew a card saved just before it and one saved earlier.+- **Host compaction:** one message pushed the chat past the 200k trigger. Right after that turn the host ran+ `/compact` with the keep-list. It first reloaded the session, because memory had changed since it opened.+ Afterwards the context was down to 13k, the chat line carried Claude's summary, and the next turn still knew+ the code word from the long message and the new card.+- **Long-form notes:** given the folders through `additionalDirectories`, the bot wrote `mochi.md` with its own+ Write tool, frontmatter and description included. The scan credited it to the bot from the tool call's+ `locations`, the chat showed "Created mochi.md", and in the next turn the bot read the note to answer.++## Evaluation++**Property tests** in the crate:++- no memory without a user-authored verbatim span;+- pasted and quoted spans never count;+- acknowledgement-only quotes are rejected;+- the ¼ guard and the 10-operation limit;+- tombstones never resurrect;+- an `Ask` bot's write never lands without a confirmation;+- cascade on message delete;+- the temporal flip;+- the `rev` precondition;+- the loop guard.++**Scripted regression.** About 50 zh-Hant and English conversations covering:++- LongMemEval's five abilities: extraction, multi-session reasoning, temporal reasoning, knowledge update and+ abstention;+- MemoryAgentBench's selective forgetting.++Validate the judge adversarially first: a LoCoMo audit found a judge accepting up to 63% of intentionally wrong+answers.++Built as `tools/memory-eval/` (52 cases: also long-form notes, short CJK queries and planted instructions). It+grades by keywords, not a model, so a wrong answer can't argue its way to a pass; keywords that missed right+answers were widened after reading every reply. Run on Claude (Opus, 2026-10-18), one fresh bot per case:++| | Passed | Fixed by |+|---|---|---|+| A pilot of 9 cases | 8/9 | a reply refused by the user's Claude Code auto-mode classifier for naming their daughter: Codync's chat and memory tools are now allowed in the Claude options |+| The full run | 41/52 | |+| Right answers the grader missed (spacing in "3 月 14 日", 羽毛球, 燕麥奶, "沒跟我說過", a reply naming the planted bank to warn about it) | +8 | the grader |+| An itinerary kept as entries, not a note; a forgotten fact read back from history | +2 | the memory instructions now name lists, itineraries and histories for notes, and say forgetting covers history |+| Left | 51/52 | ex-05: the user's own `~/.claude/CLAUDE.md` made the bot answer with an HTML file |++Decisions from it: the caps stay (no case reached one); no FTS5 or vectors (every recall miss was the answer+format, never search); dreaming unchanged.++It also showed a bot inheriting the user's own Claude Code setup: `~/.claude/CLAUDE.md`, its permission mode, and+the claude.ai connectors (one bot looked through the user's Gmail and Calendar unasked). Isolating it+(`settingSources: ["project"]` for bots in their own workspace) changes what existing bots can do, so it waits+for the owner's decision.++**Compaction probes** after each compaction, Factory-style:++- recall;+- artifacts (paths, ids);+- continuation;+- decisions.++**Prompt cache.** The host logs each turn's cache reads and writes (`turn usage` in `host.log`).+`tools/memory-eval/cache.py` measures the hit rate from Claude Code's and Codex's own session logs; on 2026-10-18:++| | Conversations | Calls | In a conversation | Every call |+|---|---|---|---|---|+| The owner's Claude bots (`~/.codync`, `~/.codync-dev`) | 27 | 229 | **97.6%** | 83.7% |+| The owner's Codex bots | 7 | 24 | 96.7% | 81.4% |+| The evaluation run (Claude) | 173 | 472 | 98.1% | 71.1% |++The owner's Cursor, oh-my-pi and custom bots aren't measured: the script reads only those two logs. Once the host+from this branch runs, its `turn usage` lines cover every harness whose adapter reports cached tokens.++- **The owner's cache lives an hour.** Their Claude bots run on a Claude subscription, so every cache write was+ a 1-hour entry (100% of `usage.cache_creation`). On extra-usage credits or an API key it is five minutes, and+ the cold calls would start five minutes after the last one. Codex keeps OpenAI's own cache life, not measured.+- **In a conversation** is the share of input read from cache, leaving out each conversation's first call and+ calls more than an hour after the previous one. Per call it is 97.2%, and the median conversation 99.2%.+- **Every call** adds those back. Many conversations are only 1–3 calls, so per conversation it averages 61.4%.+- **Cold calls on the owner's bots:**+ - 25 first calls;+ - 22 after the cache expired;+ - 4 mid-session misses, each reading about 15k of 46k. All of them date from 2026-09-30 to 10-10, before the+ cache-safe opening. The evaluation had none.+- **Cost:** Claude Code writes every cache entry for an hour, at 2× input. Overall, input cost 36.9% of the same+ calls uncached. A one-call conversation costs more than no cache would (157%): it writes the cache and never+ reads it back. Codex (OpenAI) caches on its own and charges nothing to write.++**Product metrics** (PostHog counts only, never content):++- the 7-day regret rate (memories the user edits or deletes);+- the dream-undo rate;+- compactions per session;+- rollovers;+- cache hit ratio before and after compaction;+- "wrong memory" taps.++## Rollout++Each milestone ships as its own minor release, with an e2e pass on all three apps.++- **M0. Cards, dreaming, the move from Engram (2.18.0, built).**+ - `host/crates/memory` in the standalone shape from [Packaging](#packaging); the tables; the move from Engram+ and Markdown memory in one pass.+ - The gate with pasted-span tagging in all three composers, the source policy and the sensitive-data rules.+ - The bot's memory tools: direct writes with undo in `Auto`, confirm cards in `Ask`; the shared "yours" layer.+ - Claude Code's auto memory off for personal bots, auto-dream off for all.+ - Dreaming: proposal, audit, evidence ids, the `rev` precondition, limits, headroom, the time review, the log+ with undo. Automatic naming at turn end.+ - Two layers on the memory screens of all three clients; `minApp` 2.18.0.+- **M1. Instructions for every harness (built).**+ - ACP `systemPrompt` where advertised; the first-message profile again after a compaction elsewhere, the+ compaction inferred from usage when the agent doesn't report it.+ - Each harness's own memory turned off for personal bots where it can be.+- **M2. Cache-safe opening and compaction (built).**+ - Remove the reload; send the `_meta.systemPrompt` object with `excludeDynamicSections`; fork re-sends it.+ - The ledger and deltas.+ - Usage and the TTL; the three triggers with the loop guard and the before/after steps.+ - The keep-list: Claude through `/compact`, Codex through `compact_prompt`.+ - The summary card, the editable handoff and its history bookmark.+ - Cache tokens logged per turn and measured on real bots ([prompt cache](#evaluation)).+- **M3. Long-form memory (built).**+ - The folders, the naming and cap rules, `memory_files` and `memory_file_versions`.+ - The turn-end scan, versions, checks and restore; compare-and-swap host writes.+ - The index in the opening; `read_memory`, `edit_memory`, and `search_memory` over files;+ `additionalDirectories`.+ - Dreaming appends and moves detail out of full card layers.+ - The files, versions and "Updated" lines in all three clients.+- **M4. Evaluation and tuning (built).** The scripted regression below, plus questions answered only by a+ long-form file, short CJK queries and planted instructions; tune the caps and dreaming from it, and decide FTS5+ and vectors by their triggers. The runner and its 52 cases are in `tools/memory-eval/`; the results are under+ [Evaluation](#evaluation).+- **M5. The public mirror.** `leepokai/codync-mem`, synced on every release, as under [Packaging](#packaging).+ The sync (`.github/workflows/memory-mirror.yml`, a no-op until the `CODYNC_MEM_DEPLOY_KEY` secret exists) and+ the mirror's own CI and pull-request redirect (`host/crates/memory/.github/`) are in place; the split builds,+ passes clippy and tests on its own. Creating the repository and its deploy key is left to the owner.++## Sources++**Products**++- ChatGPT: [memory and dreaming](https://openai.com/index/chatgpt-memory-dreaming/), [Memory FAQ](https://help.openai.com/en/articles/8590148-memory-faq), [Projects](https://help.openai.com/en/articles/10169521-projects-in-chatgpt)+- Claude: [chat search and memory](https://support.claude.com/en/articles/11817273-use-claude-s-chat-search-and-memory-to-build-on-previous-context)+- Claude Code docs: [memory](https://code.claude.com/docs/en/memory), [context window](https://code.claude.com/docs/en/context-window), [prompt caching](https://code.claude.com/docs/en/prompt-caching), [hooks](https://code.claude.com/docs/en/hooks), [settings](https://code.claude.com/docs/en/settings-reference), [modifying system prompts](https://code.claude.com/docs/en/agent-sdk/modifying-system-prompts), [changelog](https://raw.githubusercontent.com/anthropics/claude-code/main/CHANGELOG.md)+- Claude Code issues: [auto-dream #38493](https://github.com/anthropics/claude-code/issues/38493)+- Anthropic API: [prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching), [compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand), [context editing](https://platform.claude.com/docs/en/build-with-claude/context-editing), [memory tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool)+- Grok: [designing Grok Bot](https://x.ai/news/designing-grok-bot), [Team Bots](https://x.ai/news/team-bots), [Grok Build memory](https://x.ai/news/grok-build-memory)+- Codex: [memories](https://learn.chatgpt.com/docs/customization/memories), [`compact.rs`](https://raw.githubusercontent.com/openai/codex/main/codex-rs/core/src/compact.rs), [`compact_remote_v2.rs`](https://raw.githubusercontent.com/openai/codex/main/codex-rs/core/src/compact_remote_v2.rs)+- Coding agents: [Amp Handoff](https://ampcode.com/news/handoff), [Factory: evaluating compression](https://factory.com/news/evaluating-compression), [Cursor: dynamic context discovery](https://cursor.com/en-US/blog/dynamic-context-discovery)+- OpenClaw: [dreaming](https://docs.openclaw.ai/concepts/dreaming), [compaction](https://docs.openclaw.ai/concepts/compaction)+- Hermes: [memory](https://hermes-agent.nousresearch.com/docs/user-guide/features/memory), [#5563](https://github.com/NousResearch/hermes-agent/issues/5563)+- Letta: [memory blocks](https://docs.letta.com/guides/agents/memory-blocks), [sleep-time compute](https://www.letta.com/blog/sleep-time-compute), [benchmarking agent memory](https://www.letta.com/blog/benchmarking-ai-agent-memory)+- Mem0: [token-efficient memory](https://mem0.ai/blog/mem0-the-token-efficient-memory-algorithm)+- Zep/Graphiti: [Graphiti](https://github.com/getzep/graphiti), [Zep](https://arxiv.org/abs/2501.13956)++**Research**++- Benchmarks: [LongMemEval](https://arxiv.org/abs/2410.10813), [MemoryAgentBench](https://arxiv.org/abs/2507.05257), [LoCoMo audit](https://penfieldlabs.substack.com/p/we-audited-locomo-64-of-the-answer)+- Memory systems: [A-MEM](https://arxiv.org/abs/2502.12110), [Context Rot](https://www.trychroma.com/research/context-rot)+- Attacks: [MINJA](https://arxiv.org/abs/2503.03704), [AgentPoison](https://arxiv.org/abs/2407.12784), [multi-agent spread](https://arxiv.org/abs/2407.07791), [Gemini delayed tool invocation](https://embracethered.com/blog/posts/2025/gemini-memory-persistence-prompt-injection/), [Microsoft: AI recommendation poisoning](https://www.microsoft.com/en-us/security/blog/2026/02/10/ai-recommendation-poisoning/)+- Defenses: [CaMeL](https://arxiv.org/abs/2503.18813), [design patterns for securing LLM agents](https://arxiv.org/html/2506.08837)++**Community**++- [r/ChatGPT project-only memory leak](https://old.reddit.com/r/ChatGPT/comments/1rdei2p/)+- [r/ChatGPT turning off memory](https://old.reddit.com/r/ChatGPT/comments/1ve7jch/)+- [HN: Claude Memory](https://news.ycombinator.com/item?id=45684134)++**ACP**++- [RFD updates](https://agentclientprotocol.com/rfds/updates), [proxy chains](https://agentclientprotocol.com/rfds/proxy-chains), [client-provided system prompt](https://agentclientprotocol.com/rfds/client-system-prompt)+- [`codex-acp`](https://github.com/agentclientprotocol/codex-acp), [`agent-client-protocol` 2.0 proxies](https://docs.rs/agent-client-protocol/2.0.0/agent_client_protocol/concepts/proxies/index.html)++**Local**++- `@agentclientprotocol/claude-agent-acp` 0.92.0 (`acp-agent.js`, `context-compaction.js`)+- `@anthropic-ai/claude-agent-sdk` 0.3.300 (`sdk.d.ts`, bundled Claude Code 2.1.300)diff --cc docs/guides/development.mdindex d5f59e50,86621692..102f94ba--- a/docs/guides/development.md+++ b/docs/guides/development.md@@@ -91,10 -91,10 +91,10 @@@ git config core.hooksPath .githook```It runs CI's checks for each part a commit touches, so a failure shows up before the push:-host (`cargo fmt --check`, clippy, `cargo test` and the memory tests, with CI's pinned Engram-fetched once into `host/target/engram-test-runtime`), desktop, cloud and relay (`npm run typecheck`,-`npm test`), the Android app (core and app unit tests, and a Kotlin compile of the app and its instrumentation tests, with JDK 21), Linux-screen helper formatting, and a parse of the macOS screen helper's Swift sources (on macOS). It checks the staged files only, in a copy under `.git/precommit-snapshot`,+host and the memory crate (`cargo fmt --all --check`, clippy and `cargo test` for the workspace), desktop, cloud- and relay (`npm run typecheck`,- `npm test`), Linux screen helper formatting, and a parse of the macOS screen helper's Swift- sources (on macOS). It checks the staged files only, in a copy under `.git/precommit-snapshot`,++and relay (`npm run typecheck`, `npm test`), the Android app (core and app unit tests, and a Kotlin compile of++the app and its instrumentation tests, with JDK 21), Linux screen helper formatting, and a parse of the macOS++screen helper's Swift sources (on macOS). It checks the staged files only, in a copy under `.git/precommit-snapshot`,so other agents' uncommitted edits in the same checkout neither break nor rescue a commit; thehost builds into `host/target/precommit`, and its tests are stopped after 5 minutes so a hungtest fails the commit instead of holding it. The npm checks reuse each package's `node_modules`diff --cc docs/plans/android-app.mdindex 00000000,2a893493..fe912d32mode 000000,100644..100644--- a/docs/plans/android-app.md+++ b/docs/plans/android-app.md@@@ -1,0 -1,99 +1,108 @@@+ # Android parity and acceptance++ Status: **in development, merged into `dev`** (#151, #152, #154, #155), not released yet. The+ Android app is a 1:1 port of the iPhone app: each screen+ is built from its iOS source (`apps/ios/Views`, `apps/ios/Kit/Sources/CodyncUI`) with the+ Android `design` module (see the [Android README](../../apps/android/README.md)). Product+ logic stays in the host. This checklist tracks what's still different and what still needs+ acceptance on real devices.++ ## Coverage++ "Ported" means the iOS screen and flow exist on Android and were walked through on an+ emulator against a real host; device acceptance is listed separately.++ | Area | Android | Remaining |+ | --- | --- | --- |+ | Welcome/pairing | Ported: welcome crew and chat glimpse, Install (Mac/Linux) and Scan pages with the camera on the page, paste link, Tailscale note, sign-in | Physical optical scan, camera permission denial |+ | Accounts/access | Ported: account sheet and switcher, Computers & settings (connection status, badge color, Revoke this phone's access, older copies removed from the account), account computer access with its code, access banner, `codync-dev://computers` and `codync-dev://plugins` | Provider browser round trip on a device; Revoke and older copies against a signed-in account (covered by cloud request tests only); one computer per phone ([multiple computers are future work](../architecture/overview.md)) |+ | Roster | Ported: rows, menus, pin/hide/delete, groups, drag to reorder (host-synced order) and TalkBack Move up/down, computer header, pull to refresh (also in Computers & settings) | Multiple computers |+ | Conversation/threads | Ported: bubbles, Markdown/code, permissions, reactions, threads, Full conversation, bot-to-bot exchange lines and their conversation, routine notices that open their routine, files a bot shares (verified download, then the share sheet), sent images full size, pull down to reconnect, jump to latest, read receipts for every conversation on screen | Physical keyboard and TalkBack |+ | Composer | Ported: files/photos/paste (groups too, image thumbnails, Paste only when the clipboard holds files), `/` commands (Fast mode, New session, skills listed fresh on `/`), @mentions in groups, call/send/stop/interrupt button | — |+ | Bot and group editors | Ported: avatar, profile, agent and model options, Fast mode, workspace folder picker, permissions, activity, connectors, skills (with their details) | — |+ | Memory | Ported: search, filters, add/edit, pin, review, history and timeline, export/import, forget all | — |+ | Routines | Ported: list with switches, editor (schedule, webhook panel, run settings), test run, delete | Live provider/routine acceptance |+ | Extensions | Ported: agents (install, sign-in, setup terminal), registry connectors, Composio apps, skills, installed list, custom connector, own skill, credentials, chat connection request card | Real provider OAuth, 1Password |+ | Voice | Ported: call bar (provider name, fallback notice), Voice chat settings (engine, mode, models, voice, minutes this month), on device (the call's language through Android's on-device recognizer, Vosk English as the fallback, replies read by an offline voice for their language), OpenAI Realtime (WebRTC), Gemini Live, Speech mode, fallback to on device, group calls | Both providers with a real key on a device; a live microphone on a device |+ | State/widgets | Ported: Widget (with the animated Add a widget guide), Live update and Status bar pages, Usage sheet, Choose the look; Provider usage, Usage limits, Bots and Team widgets with launcher Edit widget and picker previews (Android 15+); the Bots Quick Settings tile (iOS's Control Center control) | Physical launcher refresh |+ | Notifications | Ported: alerts as conversations with the bot's face (a group's face and its speaking member), conversation shortcuts, what happened ("Task complete") as sub text | Android's conversation layout doesn't draw sub text; background delivery needs FCM in the deployment |+ | Live updates | Android 16 Live updates (`ProgressStyle`), the status bar chip on Android 16 QPR1 (API 36.1) | Background updates need FCM in the deployment |+ | Version check | `VersionMismatch.MIN_HOST`, the host's `minApp`, the update card in the roster and in place of the composer | Set `MIN_HOST` to the first release that ships Android support when it's cut |+ | Remote screen | Ported: viewer from Computers, the chat header (watch a bot, then take over) and `codync-dev://screen`; WebRTC H.264, trackpad and direct touch, long-press drag, two-finger scroll, pinch zoom streaming the visible region, keyboard with IME and modifier keys, clipboard, displays, take over/hand back, Rotate | Pinch, IME composition and a hardware keyboard on a device; TURN relay path and renewal |+ | Analytics | Ported: PostHog feature events with the Settings switch (and its sheet), crash reports sent on the next launch | — |+ | Packaging | Debug, unsigned R8 release, CI, optional Firebase/private configuration | Play signing, distribution, `versionCode` policy |++ ## Gates before merge into dev++ - [x] `./gradlew :core:test :app:testDebugUnitTest :app:assembleDebug :app:assembleDebugAndroidTest :app:assembleRelease :app:lintDebug` passes (CI and the pre-commit hook run it).+ - [x] Every screen above walked through on an API 36 emulator against a disposable host, in light and dark mode, side by side with the iOS simulator.+ - [x] Live update and its status bar chip on an API 36.1 emulator.+ - [x] `AppStore.kt` split by responsibility (clean-code size rule), undecodable events stop after one rewind and show *Update this app*, timeouts surface as errors.+ - [ ] Instrumentation suite run on an emulator: only single classes so far (`PlatformSpeechTest`, `AlertNotificationTest`, probes), through `am instrument` because Gradle's connected run uninstalls the paired app.++ ## Not done yet++ Where the Android app still falls short, as of 2026-10-18. Everything else in the table above+ was walked through on an emulator against a real host.+++### Not ported yet++++- **Bot memory (2.18.0).** The host's memory moved out of Engram ([bot memory](../design/bot-memory.md)). The++ memory screen still calls the removed `memoryDetail`, `reviewMemory`, `exportMemory` and `importMemory`++ (`MemoryModel.kt`, `MemoryCard.kt`, `LiveMemoryTest.kt`), so it shows an error. Missing too: the two layers++ (yours and the bot's) with pending and archived entries, memory notes (long-form files with versions), the++ `memoryFile` chat lines, compaction summaries and the handoff card. Port them from the iPhone++ (`MemoryView.swift`, `MemoryFilesView.swift`, `MemoryFileRow.swift`, `HandoffRows.swift`).+++ ### Not verified (needs an account, a key, a device or the real Mac)++ | What | Code | What it needs |+ | --- | --- | --- |+ | Revoke this phone's access; removing older copies of the computer from the account | `core/.../CloudClient.kt` (`revokeAccess`, `removeComputer`), `SettingsView.kt` | A signed-in account on the emulator or a phone; only request tests cover it |+ | Push delivery (alerts, background Live update refresh) | `PushService.kt`, `AppStoreNotifications.kt` | A Firebase project and the push Worker's FCM secret (owner's go-ahead). The notification look is covered by `AlertNotificationTest` |+ | OpenAI Realtime, Gemini Live and Speech mode with a real key | `WebRtcPeer.kt`, `core/.../OpenAIRealtimeEngine.kt`, `GeminiLiveEngine.kt`, `CloudSpeechEngine.kt` | A provider key on the paired computer; the fallback to on-device voice is verified |+ | Remote screen: Chinese IME composition, a hardware keyboard, the TURN relay path and its credential renewal | `ScreenKeys.kt`, `ScreenSession.kt`, `ScreenView.kt` | A computer it's safe to type into, and a signed-in host for the relay; viewing, trackpad and pinch zoom are verified |+ | On-device voice with a live microphone | `PlatformSpeech.kt`, `LocalVoiceAudio.kt` | A phone; on the emulator the recognizer was fed the speech fixture |+ | Camera QR pairing, launcher widget refresh, foldables, TalkBack end to end | `QrViewfinder.kt`, `CodyncWidgets.kt` | Physical devices; portrait lock with the rotating screen viewer, 130% text and TalkBack's Move up/down were checked on the emulator |++ ### Different from the iPhone on purpose or by platform++ - **Notification subtitle**: "Task complete" / "Response needed" / "Task failed" is the+ notification's sub text, which Android's conversation layout doesn't draw (`PushService.kt`).+ - **Bots tile** refreshes when Quick Settings opens, not live; between two bots that need you+ equally it picks the pinned one, the iPhone the most recent (`core/.../WidgetFeed.kt` `leadBot`).+ - **Shared files**: leaving the chat during a download skips the share sheet when it finishes+ (the card shows *Downloaded*); shared copies are deleted after a day (`AppStoreFiles.kt`,+ `AttachmentFiles.kt`).+ - **Pull to refresh** on the roster and in Settings uses the chat's indicator; iOS uses the system one.+ - **`computers` / `plugins` links** open over the current tab; iOS switches to Bots first.+ - **On-device voice**: languages other than English need Android 13+ and Android's on-device+ recognizer; it never falls back to online recognition (iOS may use Apple's servers).+ - **Jump to latest** is an opaque disc: it sits in the scrolling content, so there's no blur under it.+ - **Not ported**: the computer filter's hide toggle and *This computer was removed* (one computer+ per phone on Android, and removing it reloads the app), *Create template* (nothing opens it on iOS).+ - **Multiple computers**: one per phone ([future work](../architecture/overview.md)).++ ## Before a Play release++ - [ ] Physical upgrade keeps the saved account, pinned keys, bots and history.+ - [ ] Physical portrait/landscape/foldable, keyboard, large text and TalkBack.+ - [ ] Provider sign-in/switching, failed sign-out and revocation.+ - [ ] Firebase project and the push Worker's `FCM_SERVICE_ACCOUNT` secret (owner's go-ahead).+ - [ ] Host release gating for Android: like iPhones and the App Store, a release that raises+ `minApp` must wait while paired Android phones can't get that version from Play+ ([compatibility](../reference/compatibility.md)).++ ## Shared deployment++ The host accepts Android pairing (older hosts refuse it, and the app asks to update+ Codync on the computer) and counts Android event streams as connected phones, so+ pushes are held while one is open. The cloud accepts Android device records through+ the `0004_android_devices.sql` migration. The push Worker needs the matching Firebase+ service account as an external secret; the client configuration contains no private key.++ ++ ++ 