# pi-mem-cc

**Automatic observer-based memory for [pi](https://github.com/badlogic/pi-mono) coding agent.**

Inspired by [claude-mem](https://github.com/thedotmack/claude-mem) for Claude Code, but built natively for pi's extension API. Silently watches every tool call, compresses it into a structured observation, stores it in SQLite, and re-injects relevant past context at session start.

## What's different from `pi-memory` (jayzeng)?

| | `pi-memory` | `pi-mem-cc` |
|---|---|---|
| Memory capture | **Manual** — agent/user calls `memory_write` | **Automatic** — every tool call observed |
| Storage | Plain markdown files | SQLite + FTS5 |
| Search | Optional qmd (external dep) | Built-in hybrid (keyword + recency) |
| Injection | Agent must call `memory_read` | Auto-injected at session start |
| Use case | Personal knowledge book | Cross-session continuity |

Use both. They cover different needs.

## Install

```bash
pi install npm:pi-mem-cc
```

Then `/reload`.

## Tools registered

| Tool | Purpose | Token cost |
|---|---|---|
| `mem_search` | Get compact index of matching observations | ~50-100 tok/result |
| `mem_timeline` | Get chronological context around an observation id | variable |
| `mem_get` | Fetch full observation details by IDs | ~500-1000 tok/each |

**3-layer progressive disclosure** — `search` first, `timeline` for context, `get` only for filtered IDs.

## Storage

```
~/.pi/agent/memory/pi-mem-cc.db   # SQLite (observations, summaries, FTS5)
```

## How it works

1. **session_start** → register session in DB
2. **before_agent_start** → query top-K relevant past observations (recency × project match), append markdown to system prompt
3. **tool_result** → fire-and-forget compress into `<observation>` via observer LLM, write to DB
4. **agent_end** → fire-and-forget compress turn into `<summary>` via observer LLM, write to DB

The observer LLM uses the **same model as the active session** — no extra API key needed.

## Configuration

No configuration. Uses your active session model.

## License

Apache-2.0
