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
docs: record how well bots' prompt cache holds, with a script to measure it
leepokaibd9c1580ba97
diff --git a/docs/design/bot-memory.md b/docs/design/bot-memory.mdindex bc2fd1e0..5f92d3dc 100644--- a/docs/design/bot-memory.md+++ b/docs/design/bot-memory.md@@ -774,7 +774,25 @@ for the owner's decision.- continuation;- decisions.-Also log the cache read/write ratio per turn and assert on it in e2e.+**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 own session logs; on 2026-10-18:++| | Conversations | Calls | In a conversation | Every call |+|---|---|---|---|---|+| The owner's bots (`~/.codync`, `~/.codync-dev`) | 27 | 229 | **97.6%** | 83.7% |+| The evaluation run | 173 | 472 | 98.1% | 71.1% |++- **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.**Product metrics** (PostHog counts only, never content):@@ -808,7 +826,7 @@ Each milestone ships as its own minor release, with an e2e pass on all three app- 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 asserted in e2e.+ - 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.diff --git a/tools/memory-eval/README.md b/tools/memory-eval/README.mdindex cfb8f664..9c9a73c0 100644--- a/tools/memory-eval/README.md+++ b/tools/memory-eval/README.md@@ -20,3 +20,15 @@ tools/memory-eval/run.py --home /tmp/eval-home --only tm,lf-01 # some kinds orIt prints a pass count per kind and each failure with the reply; `results.json` keeps every reply, entry and notename. Temporal answers are written as `{d+3:%Y-%m-%d}`, `{next_friday:…}` or `{next_month:%B}` and expanded onthe day of the run.++## Prompt cache++`cache.py` reads Claude Code's session logs (`~/.claude/projects`) and prints how much of each conversation's input+came from the prompt cache, why the cold calls were cold, and the input cost against no cache. It needs no host:++```sh+tools/memory-eval/cache.py # the bots of ~/.codync and ~/.codync-dev+tools/memory-eval/cache.py eval-home-bots # session folders whose name contains this+```++The latest numbers are under [prompt cache](../../docs/design/bot-memory.md#evaluation).diff --git a/tools/memory-eval/cache.py b/tools/memory-eval/cache.pynew file mode 100755index 00000000..4f94ad34--- /dev/null+++ b/tools/memory-eval/cache.py@@ -0,0 +1,100 @@+#!/usr/bin/env python3+"""How well Claude bots' prompt cache holds, read from Claude Code's own session logs.++Each session file in ~/.claude/projects is one conversation; each API call in it is counted once.+Usage: tools/memory-eval/cache.py [folder-name-part ...] (default: the bots of ~/.codync and ~/.codync-dev)+"""+import glob+import json+import os+import sys+from collections import Counter+from datetime import datetime+from statistics import mean, median++ROOT = os.path.expanduser('~/.claude/projects')+LIFE = 3600 # Claude Code writes 1-hour cache entries.+++def calls(path, seen):+ """(read, total input, 1h writes, writes, model, seconds since the previous call) per API call."""+ prev = None+ for line in open(path, errors='replace'):+ try:+ rec = json.loads(line)+ except ValueError:+ continue+ msg = rec.get('message') if isinstance(rec, dict) else None+ if not isinstance(msg, dict) or msg.get('role') != 'assistant' or 'usage' not in msg:+ continue+ key = msg.get('id') or rec.get('uuid')+ if key in seen: # a forked session repeats its parent's calls+ continue+ seen.add(key)+ u = msg['usage']+ read = u.get('cache_read_input_tokens') or 0+ write = u.get('cache_creation_input_tokens') or 0+ total = read + write + (u.get('input_tokens') or 0)+ if total == 0:+ continue+ ts = datetime.fromisoformat(rec['timestamp'].replace('Z', '+00:00'))+ gap = (ts - prev).total_seconds() if prev else None+ prev = ts+ w1h = (u.get('cache_creation') or {}).get('ephemeral_1h_input_tokens') or 0+ yield read, total, w1h, write, msg.get('model', ''), gap+++def cost(read, total, w1h, write, model):+ """Input cost at API list multipliers: read 0.1x (0.05x on the 5.5 models), 5-minute write 1.25x, 1-hour 2x."""+ return total - read - write + 1.25 * (write - w1h) + 2 * w1h + (0.05 if '-5-5' in model else 0.1) * read+++def main():+ parts = sys.argv[1:] or ['-codync-bots-', '-codync-dev-bots-']+ sessions, causes, sums = [], Counter(), Counter()+ for folder in glob.glob(os.path.join(ROOT, '*')):+ if not any(p in os.path.basename(folder) for p in parts):+ continue+ seen = set()+ for path in glob.glob(os.path.join(folder, '*.jsonl')):+ rows = list(calls(path, seen))+ if rows:+ sessions.append(rows)+ if not sessions:+ sys.exit('no sessions found')+ every, warm, per_every, per_warm = [], [], [], []+ for rows in sessions:+ hot = [r for r in rows if r[5] is not None and r[5] <= LIFE]+ every += rows+ warm += hot+ per_every.append(sum(r[0] for r in rows) / sum(r[1] for r in rows))+ if hot:+ per_warm.append(sum(r[0] for r in hot) / sum(r[1] for r in hot))+ for read, total, w1h, write, model, gap in rows:+ sums['w1h'] += w1h+ sums['write'] += write+ sums['cost'] += cost(read, total, w1h, write, model)+ if read >= total / 2:+ continue+ causes['first call' if gap is None else 'after the cache expired' if gap > LIFE else 'mid-session miss'] += 1++ def pct(x):+ return f'{100 * x:5.1f}%'++ def line(name, rows, per):+ by_tokens = sum(r[0] for r in rows) / sum(r[1] for r in rows)+ return (f'{name:<22} {pct(by_tokens):>9} {pct(mean(r[0] / r[1] for r in rows)):>8} '+ f'{pct(mean(per)):>11} {pct(median(per)):>9}')++ total = sum(r[1] for r in every)+ print(f'{len(sessions)} conversations, {len(every)} calls, {total / 1e6:.2f}M input tokens\n')+ print(f"{'hit rate':<22} {'by tokens':>9} {'per call':>8} {'per session':>11} {'median':>9}")+ print(line('in a conversation', warm, per_warm))+ print(line('every call', every, per_every))+ print('\n"in a conversation" leaves out each first call and calls more than an hour after the previous one.')+ print(f'cold calls (under half read from cache): {dict(causes)}')+ print(f"1-hour writes: {pct(sums['w1h'] / max(sums['write'], 1))} of cache writes; "+ f"input cost vs. uncached: {pct(sums['cost'] / total)}")+++main()