Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ personakit list # see what
personakit stats # counts only, never memory text
personakit tidy # plan: archive unconfirmed memories unseen for 90 days
personakit tidy --apply # carry the plan out (reverse any with `personakit undo <id>`)
personakit digest # what changed in the last 7 days (local, prints memory text)
personakit serve # MCP server over stdio for your assistants
personakit forget <memory-id> # delete a memory and its quotes for good
```

`sweep`, `list`, `stats` and `tidy` also take `--json` for stable, sorted machine-readable output.
`sweep`, `list`, `stats`, `tidy` and `digest` also take `--json` for stable, sorted machine-readable output.

The model name is always yours to choose. Nothing leaves your machine except the turns you wrote,
sent to the model you named. See [docs/PRIVACY.md](docs/PRIVACY.md).
Expand Down Expand Up @@ -140,6 +141,7 @@ Stated plainly, so you know what you are installing:
| Codex sessions | Available in 0.1 |
| Any MCP client (read and propose) | Available in 0.1 |
| Decay of stale unconfirmed memories (reversible) | Available in 0.2 |
| Digest of the last days | Available in 0.2 |
| ChatGPT, claude.ai and Gemini export import | Planned for 0.3 |

## Documentation
Expand Down
3 changes: 3 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ flowchart TB
MCP[mcp_server]
SS[stats: local counts]
TD[tidy: decay, on request]
DG[digest: last days, local]
end
CC --> IN
CX --> IN
Expand All @@ -28,6 +29,7 @@ flowchart TB
ST --> MCP
ST --> SS
ST <--> TD
ST --> DG
MCP --> AS[Assistants]
```

Expand All @@ -46,6 +48,7 @@ flowchart TB
| `mcp_server` | Two tools for assistants: `personakit_read` and `personakit_propose`. Holds no read-policy constants of its own. Assistants cannot approve, restrict, hide or forget; only the owner can, in `review`. | `store`, `retrieve`, `extract` |
| `decay` | Finds unconfirmed memories not seen again for a long time (90 days by default). Pure functions. | `model` |
| `tidy` | Turns `decay` into a plan (read-only), applies it only on request, and reverses single steps. | `decay`, `store` |
| `digest` | A summary of the last days: new and archived memories, what awaits review, read counts. Prints memory text, never quotes, to your terminal only. | `store`, `decay` |
| `stats` | Counts only (memories by state, sessions extracted, reads and how many returned something). Never content. | `store` |
| `cli` | Argument parsing and wiring; no logic. | all |

Expand Down
2 changes: 2 additions & 0 deletions docs/PRIVACY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
- **Tidy and undo:** `personakit tidy` reads your store and, only with `--apply`, archives stale
unconfirmed memories. `personakit undo` brings one back. Nothing leaves your machine, nothing
here calls a model, and assistants cannot archive or restore.
- **Digest:** `personakit digest` prints memory ids and text (never evidence quotes) to your
terminal. Unlike `stats` it is not counts-only, so look before pasting it anywhere.
1 change: 1 addition & 0 deletions docs/REVIEW-LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ duplicated logic. Each entry records the result.
| `tests/*` (new) | 2026-11-08 | invented data; a key-shaped string is assembled at runtime | clean |
| `personakit/decay.py`, `tidy.py`; `store.py`, `model.py`, `mcp_server.py`, `cli.py` (changes) | 2026-11-14 | none; migration 3 adds `last_seen_at`; an assistant proposal cannot revive or refresh a memory. Checked on a copy of a real store: upgrade, archive, undo and reads behave as documented | clean |
| `tests/test_decay.py`, `test_store_decay.py`, `test_tidy.py`; `test_cli.py`, `test_mcp_server.py` (changes) | 2026-11-14 | invented sentences only | clean |
| `personakit/digest.py`, `tests/test_digest.py`; `store.py`, `cli.py` (changes) | 2026-11-14 | none; local output only, text without quotes; invented test data | clean |
15 changes: 14 additions & 1 deletion personakit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
from pathlib import Path

from personakit import decay, llm, mcp_server, review, stats, sweep, tidy
from personakit import decay, digest, llm, mcp_server, review, stats, sweep, tidy
from personakit.ingest import ADAPTERS
from personakit.model import State
from personakit.store import Store
Expand Down Expand Up @@ -53,6 +53,10 @@ def build_parser() -> argparse.ArgumentParser:
undo_cmd = sub.add_parser("undo", help="bring back one memory that tidy archived")
undo_cmd.add_argument("memory_id")

digest_cmd = sub.add_parser("digest", help="what changed in the last days (prints memory text, locally)")
digest_cmd.add_argument("--days", type=int, default=7)
digest_cmd.add_argument("--json", action="store_true", help="print a JSON object")

forget = sub.add_parser("forget", help="permanently delete a memory and its quotes")
forget.add_argument("memory_id")

Expand Down Expand Up @@ -96,6 +100,15 @@ def _dispatch(args: argparse.Namespace, store: Store) -> int:
print(f"Nothing to undo for {args.memory_id}: tidy did not archive it", file=sys.stderr)
return 1
print("Restored.")
elif args.command == "digest":
if not 1 <= args.days <= MAX_DAYS:
print(f"--days must be between 1 and {MAX_DAYS}", file=sys.stderr)
return 2
collected = digest.collect(store, store.now(), args.days)
if args.json:
_print_json(collected)
else:
print(digest.format_digest(collected))
elif args.command == "forget":
if not store.forget(args.memory_id):
print(f"No memory with id {args.memory_id}", file=sys.stderr)
Expand Down
51 changes: 51 additions & 0 deletions personakit/digest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""A short summary of the last few days in your own store.

Unlike `stats`, a digest shows memory ids and text (never evidence quotes) so you can see what
changed. It is printed to your terminal and goes nowhere else. Run it weekly from cron or a
scheduler if you want a routine; PersonaKit does not schedule anything itself.
"""

from __future__ import annotations

from personakit import decay
from personakit.model import Decider, Memory, State
from personakit.store import Store

LISTED = 10 # most memories shown per section


def collect(store: Store, now: str, days: int = 7) -> dict:
since = decay.days_ago(now, days)
everything = store.list()
new = [m for m in everything if (m.created_at or "") >= since]
archived = [
m for m in everything if m.state == State.ARCHIVED and m.decided_by == Decider.POLICY and (m.decided_at or "") >= since
]
return {
"days": days,
"new": len(new),
"new_items": _items(new),
"archived_by_decay": len(archived),
"archived_items": _items(archived),
"awaiting_review": store.counts()[State.UNCONFIRMED.value],
**store.read_stats(since),
}


def _items(memories: list[Memory]) -> list[dict[str, str]]:
return [{"id": m.id, "text": m.text} for m in memories[:LISTED]]


def format_digest(data: dict) -> str:
lines = [f"PersonaKit digest, last {data['days']} days"]
for label, count, items in (
("New memories", data["new"], data["new_items"]),
("Archived as stale (undo with `personakit undo <id>`)", data["archived_by_decay"], data["archived_items"]),
):
lines.append(f"{label}: {count}")
lines += [f" {item['id']} {item['text']}" for item in items]
if count > len(items):
lines.append(f" ... and {count - len(items)} more")
lines.append(f"Awaiting your review: {data['awaiting_review']}")
lines.append(f"Assistant reads: {data['reads']} ({data['reads_with_results']} returned something)")
return "\n".join(lines)
5 changes: 3 additions & 2 deletions personakit/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ def log_read(self, returned: int, withheld: int) -> None:

# -- reading --------------------------------------------------------------------

def read_stats(self) -> dict[str, int]:
def read_stats(self, since: str | None = None) -> dict[str, int]:
row = self._conn.execute(
"SELECT COUNT(*) AS reads, COALESCE(SUM(returned > 0), 0) AS with_results FROM reads"
"SELECT COUNT(*) AS reads, COALESCE(SUM(returned > 0), 0) AS with_results FROM reads WHERE at >= ?",
(since or "",),
).fetchone()
return {"reads": row["reads"], "reads_with_results": row["with_results"]}

Expand Down
6 changes: 6 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def test_tidy_json_lists_ids_only(self):
def test_nothing_to_tidy_on_a_fresh_store(self):
self.assertIn("Nothing to tidy.", self.run_cli("tidy")[1])

def test_digest_prints_text_or_json_and_rejects_bad_numbers(self):
self.seed()
self.assertIn("PersonaKit digest, last 7 days", self.run_cli("digest")[1])
self.assertEqual(json.loads(self.run_cli("digest", "--days", "36500", "--json")[1])["new"], 2)
self.assertEqual(self.run_cli("digest", "--days", "-5")[0], 2)

def test_tidy_rejects_bad_numbers(self):
self.assertEqual(self.run_cli("tidy", "--days", "0")[0], 2)
self.assertEqual(self.run_cli("tidy", "--days", "99999999")[0], 2)
Expand Down
47 changes: 47 additions & 0 deletions tests/test_digest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import unittest

from personakit import digest, tidy
from personakit.model import Evidence, Memory
from personakit.store import Store

NOW = "2026-06-01T00:00:00Z"


def mem(text, turn=0):
return Memory(text=text, category="other", evidence=(Evidence("s1", turn, f"quote {turn}"),))


class DigestTest(unittest.TestCase):
def setUp(self):
self.clock = ["2026-01-01T00:00:00Z"]
self.store = Store(":memory:", now=lambda: self.clock[0])
self.addCleanup(self.store.close)

def test_digest_covers_only_the_window_and_lists_ids_with_text(self):
self.store.add(mem("You are an old memory about tabs."))
self.store.log_read(1, 0)
self.clock[0] = "2026-05-30T00:00:00Z"
recent = mem("You prefer direct, practical feedback.", turn=1)
self.store.add(recent)
self.store.log_read(2, 0)
self.store.log_read(0, 0)
data = digest.collect(self.store, NOW, days=7)
self.assertEqual((data["new"], data["reads"], data["reads_with_results"], data["awaiting_review"]), (1, 2, 1, 2))
self.assertEqual(data["new_items"], [{"id": recent.id, "text": recent.text}])
text = digest.format_digest(data)
self.assertIn(recent.id, text)
self.assertIn("Awaiting your review: 2", text)
self.assertNotIn("quote", text)

def test_digest_shows_what_decay_archived_and_caps_long_lists(self):
for i in range(digest.LISTED + 2):
self.store.add(mem(f"You track item number {i} in notes.", turn=i))
self.clock[0] = NOW
tidy.apply(self.store, tidy.make_plan(self.store, NOW, days=30))
data = digest.collect(self.store, NOW, days=7)
self.assertEqual((data["archived_by_decay"], len(data["archived_items"])), (digest.LISTED + 2, digest.LISTED))
self.assertIn("... and 2 more", digest.format_digest(data))


if __name__ == "__main__":
unittest.main()
Loading