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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ personakit sweep --cli claude --model <model-name> --max-calls 20 # read sessi
personakit review # optional: approve, restrict, hide, forget
personakit list # see what is stored
personakit stats # counts only, never memory text
personakit tidy # plan: archive unconfirmed memories unseen for 90 days
personakit tidy # plan: fold near-identical twins, archive stale memories
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
Expand Down Expand Up @@ -104,8 +104,8 @@ Your assistant gets two tools:
4. **Review** is optional. Memories you never review are served marked *unconfirmed*; you
can approve, restrict, hide or forget any of them at any time.
5. **Serve** exposes the store to assistants over MCP, with the evidence attached.
6. **Tidy** (on request) archives unconfirmed memories not seen again for 90 days. It shows a
plan first; nothing changes without `--apply`, nothing is deleted, and `personakit undo <id>`
6. **Tidy** (on request) folds near-identical memories into one, and
archives unconfirmed memories not seen again for 90 days. It shows a plan first; nothing changes without `--apply`, nothing is deleted, and `personakit undo <id>`
reverses a step.

A memory is always in one of four states:
Expand All @@ -126,6 +126,9 @@ Stated plainly, so you know what you are installing:
in other scripts are not matched yet; approved memories are still returned as standing context.
- **A decision cannot be changed, only undone by forgetting.** `review` shows unconfirmed memories;
there is no command yet to edit a memory's wording or move a decided memory to another state.
- **Twin detection compares words, not meaning.** It folds memories phrased almost the same way,
from any session, and misses paraphrases on purpose: a missed merge costs nothing, a wrong
one costs trust. Expect it to find little when the same fact is worded differently each time.
- **Decay looks only at time.** An unconfirmed memory not extracted again for 90 days is archived
(reversible); that says nothing about whether it is still true. Approved and restricted
memories never decay.
Expand All @@ -140,6 +143,7 @@ Stated plainly, so you know what you are installing:
| Claude Code sessions | Available in 0.1 |
| Codex sessions | Available in 0.1 |
| Any MCP client (read and propose) | Available in 0.1 |
| Merge of near-identical memories (reversible) | Available in 0.2 |
| 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 |
Expand Down
24 changes: 16 additions & 8 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ flowchart TB
RV[review: CLI]
MCP[mcp_server]
SS[stats: local counts]
TD[tidy: decay, on request]
TD[tidy: twins + decay, on request]
DG[digest: last days, local]
end
CC --> IN
Expand Down Expand Up @@ -46,10 +46,11 @@ flowchart TB
| `store` | The only module that touches SQLite. Schema, migrations, queries, state changes. | `model` |
| `review` | Terminal UI over the store: approve, restrict, hide, forget. Optional by design. | `store` |
| `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` |
| `twins` | Finds near-identical unconfirmed memories of one category and scope, across sessions. Word-based, deliberately cautious (the order of shared words must agree); numbers and negation must agree whatever scores a pair. Pure functions. | `model`, `retrieve` |
| `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` |
| `plugins` | One extension point, `relevance`, loaded only when the owner names a plugin in `PERSONAKIT_PLUGINS`. A plugin scores; policy stays in `retrieve` and `store`. See [PLUGINS.md](PLUGINS.md). | `retrieve` |
| `tidy` | Turns `twins` and `decay` into a plan (read-only), applies it only on request, and reverses single steps. | `twins`, `decay`, `store` |
| `digest` | A summary of the last days: new, merged and archived memories, what awaits review, read counts. Prints memory text, never quotes, to your terminal only. | `store`, `decay` |
| `plugins` | Two extension points, `relevance` and `similarity`, loaded only when the owner names a plugin in `PERSONAKIT_PLUGINS`. A plugin scores; policy stays in `retrieve`, `twins` and `store`. See [PLUGINS.md](PLUGINS.md). | `retrieve`, `twins` |
| `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 All @@ -61,6 +62,10 @@ model, only `ingest` reads session files.** A second implementation of any of th
- **Turn**: `(source, session_id, index, timestamp, text)`. Only owner-authored turns exist here.
- **Memory**: `id, text, category, scope, state, created_at, last_seen_at, decided_at, decided_by`.
`last_seen_at` moves forward each time the same statement is extracted again.
- **Merge**: a folded memory keeps its own row and evidence and points at the memory it was folded
into (`merged_into`, `merged_at`). It is not listed or served on its own; the surviving memory
shows the evidence of both. `undo` clears the pointer, so it is exact, and remembers the pair so
it is not proposed again. `forget` on either memory removes that memory's rows for good.
- **Evidence**: `memory_id, session_id, turn_index, quote`. Every memory has at least one.
- **State**: `unconfirmed` (default, served with a label) -> `approved` | `restricted` |
`archived`. Nothing is ever hard-deleted without an explicit `forget` by the owner.
Expand All @@ -71,9 +76,10 @@ model, only `ingest` reads session files.** A second implementation of any of th
2. Unconfirmed memories are served, labelled as unconfirmed. Review is a quality tool, not a gate.
3. The system never deletes a memory, and never touches a memory you have decided on. Extracting
the same statement again adds evidence to the existing memory and leaves your decision alone.
One thing changes unconfirmed memories, and only when you run `personakit tidy --apply` (the
default is a plan that changes nothing): archiving memories not seen again for 90 days. It is
reversible with `personakit undo <id>`, and a memory that decay archived comes back by itself
Two things change unconfirmed memories, and only when you run `personakit tidy --apply` (the
default is a plan that changes nothing): folding near-identical twins together, and archiving
memories not seen again for 90 days. Both are reversible with `personakit undo <id>`, and a
memory that decay archived comes back by itself
if the statement is extracted again from your own words. An assistant proposing the same text
does not bring it back and does not reset its age.
4. Only text the owner wrote is sent to a model.
Expand All @@ -86,4 +92,6 @@ See the roadmap for what is planned.

## Limits in 0.2

Decay looks only at how long ago a statement was last extracted, not at whether it is still true.
Twin detection compares words, not meaning. It catches the same statement phrased almost the
same way and misses paraphrases; it is built to miss rather than to merge wrongly. On stores
where the same fact is worded differently each time it finds little. Decay looks only at how long ago a statement was last extracted, not at whether it is still true.
16 changes: 10 additions & 6 deletions docs/PLUGINS.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# Plugins

PersonaKit has one extension point. It replaces a scoring function and nothing else.
PersonaKit has two extension points. Both replace a scoring function and nothing else.

| Hook | Signature | Built-in | Used by |
|---|---|---|---|
| `relevance` | `(question: str, memories: Sequence[Memory]) -> Sequence[float]` | word overlap | `personakit serve` (which memories answer a question, and in what order) |
| `similarity` | `(a: str, b: str) -> float` between 0 and 1 | shared words, with number, negation and order guards | `personakit tidy` (which memories are twins) |

## What a plugin cannot do

Policy stays in the core, whatever a plugin returns:

- Restricted and archived memories are never served. A relevance score only orders what the read
policy already allows.
- No hook can approve, restrict, archive or forget.
- Only unconfirmed memories with the same category and scope, none resting on an assistant's
proposal, can be proposed as twins, and only when they mention the same numbers and agree on
negation. Merging still needs `personakit tidy --apply` and is reversible.
- No hook can approve, restrict, archive, restore or forget.

A plugin is still Python code running as you, with access to your store file. Enable only
plugins you trust and have read.
Expand All @@ -24,7 +28,7 @@ Nothing is loaded just because it is installed. Name the plugins you want:
```sh
pip install some-personakit-plugin
export PERSONAKIT_PLUGINS=some-name # comma separated for several, applied in order
personakit serve
personakit tidy
```

A name that is not installed is an error, not a silent fallback.
Expand All @@ -43,9 +47,9 @@ some-name = "some_package:register"
```python
# some_package/__init__.py
def register(hooks):
hooks.relevance = my_relevance
hooks.similarity = my_similarity # leave hooks.relevance alone to keep the built-in
```

For anything beyond scoring, use PersonaKit as a library: `personakit.store.Store` is the one
place that reads and writes the database, and `Store.set_state` is the same operation the CLI
uses.
place that reads and writes the database, and `Store.merge`, `Store.undo_merge`,
`Store.set_state` and `Store.restore` are the same reversible operations the CLI uses.
11 changes: 7 additions & 4 deletions docs/PRIVACY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
- **Statistics:** `personakit stats` prints counts to your terminal. It never includes memory text.
Sharing the output is your choice.
- **Deletion:** `personakit forget` removes a memory and its evidence from the store.
- **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.
- **Tidy and undo:** `personakit tidy` reads your store and, only with `--apply`, folds
near-identical memories together and archives stale ones. A folded memory stays in your store
with its own quotes, so `personakit undo` restores it exactly. `personakit forget` on a folded
memory deletes it and every quote it brought; `forget` on the memory it was folded into deletes
both, since they are the same statement. Nothing leaves your machine, and nothing here calls a
model. Assistants cannot merge, undo, 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.
- **Plugins:** none are loaded unless you name them in `PERSONAKIT_PLUGINS`. A plugin replaces
how relevance is scored and cannot change what is served, but it is code you installed, running
how relevance or similarity is scored and cannot change what is served or what may be merged, but it is code you installed, running
as you. What it does with your data is up to that plugin; read it first.
3 changes: 3 additions & 0 deletions docs/REVIEW-LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ duplicated logic. Each entry records the result.
| `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 |
| `personakit/plugins.py`, `docs/PLUGINS.md`, `tests/test_plugins.py`; `retrieve.py`, `mcp_server.py`, `cli.py` (changes) | 2026-11-14 | none; opt-in by name, scoring only, a policy test proves a plugin cannot widen what is served | clean |
| `personakit/twins.py`; `store.py`, `tidy.py`, `digest.py`, `cli.py`, `model.py`, `review.py`, `mcp_server.py`, `retrieve.py` (changes) | 2026-11-14 | none; written for this repository, word-based only, thresholds chosen from invented examples. Migration 4 adds `merged_into` and `merge_vetoes`; a folded memory keeps its own rows, so forget leaves nothing behind. Security and code review findings fixed, each with a regression test | clean |
| `tests/test_twins.py`, `test_merge_store.py`; `test_tidy.py`, `test_cli.py`, `test_digest.py` (changes) | 2026-11-14 | invented sentences only | clean |
| `personakit/twins.py`, `plugins.py`, `cli.py` (changes); `tests/test_twins.py`, `test_plugins.py` | 2026-11-16 | none; twins are compared across sessions, a `similarity` hook is added, and numbers and negation must agree whatever scores a pair. Invented sentences only | clean |
5 changes: 1 addition & 4 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
| Release | Scope | Target |
|---|---|---|
| 0.1 | Claude Code + Codex ingest, extract, store, CLI review, MCP server, local stats | day 10 |
| 0.2 | Decay to archive (reversible), weekly digest, a relevance extension point | in review |
| 0.2 | Merge near-identical duplicates (reversible), decay to archive, weekly digest, extension points for relevance and similarity | in review |
| 0.3 | Import from ChatGPT / claude.ai / Gemini exports | after launch |
| 0.4 | Third-party name guard | after launch |

Merging duplicate memories was planned for 0.2 and is on hold: matching by shared words found
no duplicates on a real store, because the same fact is usually worded differently each time.

Dates are estimates. Each release ships only after the contributing code has been reviewed
for personal data and for duplicate logic.

Expand Down
57 changes: 40 additions & 17 deletions 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, digest, llm, mcp_server, plugins, review, stats, sweep, tidy
from personakit import decay, digest, llm, mcp_server, plugins, review, stats, sweep, tidy, twins
from personakit.ingest import ADAPTERS
from personakit.model import State
from personakit.store import Store
Expand Down Expand Up @@ -45,14 +45,18 @@ def build_parser() -> argparse.ArgumentParser:
stats_cmd = sub.add_parser("stats", help="counts only, never memory text")
stats_cmd.add_argument("--json", action="store_true", help="print a JSON object")

tidy_cmd = sub.add_parser("tidy", help="archive stale unconfirmed memories (shows a plan; --apply to act)")
tidy_cmd = sub.add_parser("tidy", help="fold near-identical twins and archive stale memories (shows a plan; --apply to act)")
tidy_cmd.add_argument("--apply", action="store_true", help="carry out the plan instead of only showing it")
tidy_cmd.add_argument("--days", type=int, default=decay.DEFAULT_DAYS, help="days unseen before unconfirmed is stale")
tidy_cmd.add_argument("--threshold", type=float, default=twins.DEFAULT_THRESHOLD, help="twin similarity, 0 to 1")
tidy_cmd.add_argument("--only", choices=["merge", "archive"], default=None, help="do just one of the two steps")
tidy_cmd.add_argument("--json", action="store_true", help="print a JSON object (ids only)")

undo_cmd = sub.add_parser("undo", help="bring back one memory that tidy archived")
undo_cmd = sub.add_parser("undo", help="reverse one merge or one stale-archive by memory id")
undo_cmd.add_argument("memory_id")

sub.add_parser("merges", help="list memories that were merged into another, with their ids")

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")
Expand Down Expand Up @@ -99,11 +103,13 @@ def _dispatch(args: argparse.Namespace, store: Store) -> int:
return _tidy(args, store)
elif args.command == "undo":
try:
tidy.undo(store, args.memory_id)
print(tidy.undo(store, args.memory_id).capitalize() + ".")
except KeyError:
print(f"Nothing to undo for {args.memory_id}: tidy did not archive it", file=sys.stderr)
print(f"Nothing to undo for {args.memory_id}: not a merged or stale-archived memory", file=sys.stderr)
return 1
print("Restored.")
elif args.command == "merges":
for record in store.merges():
print(f"{record.duplicate_id} into {record.survivor_id} {record.duplicate_text}")
elif args.command == "digest":
if not 1 <= args.days <= MAX_DAYS:
print(f"--days must be between 1 and {MAX_DAYS}", file=sys.stderr)
Expand All @@ -129,23 +135,40 @@ def _print_json(data: object) -> None:


def _tidy(args: argparse.Namespace, store: Store) -> int:
if not 1 <= args.days <= MAX_DAYS:
print(f"--days must be between 1 and {MAX_DAYS}", file=sys.stderr)
if not 1 <= args.days <= MAX_DAYS or not 0 < args.threshold <= 1:
print(f"--days must be between 1 and {MAX_DAYS} and --threshold between 0 and 1", file=sys.stderr)
return 2
plan = tidy.make_plan(store, store.now(), args.days)
if args.apply:
tidy.apply(store, plan)
plan = tidy.make_plan(
store,
store.now(),
args.days,
args.threshold,
merge=args.only != "archive",
archive=args.only != "merge",
similarity=plugins.load().similarity,
)
report = tidy.apply(store, plan) if args.apply else None
if args.json:
_print_json({"applied": args.apply, "archive": [m.id for m in plan.stale]})
_print_json(
{
"applied": report is not None,
"merge": [{"keep": g.survivor.id, "fold": [d.id for d in g.duplicates]} for g in plan.groups],
"archive": [m.id for m in plan.stale],
}
)
return 0
for group in plan.groups:
print(f"keep {group.survivor.id} {group.survivor.text}")
for duplicate in group.duplicates:
print(f" fold {duplicate.id} {duplicate.text}")
for memory in plan.stale:
print(f"archive {memory.id} {memory.text}")
if not plan.stale:
print("Nothing to tidy.")
elif args.apply:
print(f"Archived {len(plan.stale)}. Reverse any with: personakit undo <id>")
if report:
print(f"Merged {report.merged}, archived {report.archived}. Reverse any with: personakit undo <id>")
elif plan.groups or plan.stale:
print(f"{plan.merges} to merge, {len(plan.stale)} to archive. Nothing changed; add --apply to carry it out.")
else:
print(f"{len(plan.stale)} to archive. Nothing changed; add --apply to carry it out.")
print("Nothing to tidy.")
return 0


Expand Down
Loading
Loading