Metadata-Version: 2.4
Name: atelya-attest
Version: 0.2.0
Summary: Tamper-evident audit trail for AI-agent memory — hash-chained attestation + transparency-log checkpoints (RFC 6962 / C2SP pattern). Zero dependencies.
Author: Atelya OS contributors
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/RonaldSit/atelya
Project-URL: Source, https://github.com/RonaldSit/atelya
Project-URL: Issues, https://github.com/RonaldSit/atelya/issues
Keywords: ai,agents,memory,audit,tamper-evident,compliance,transparency-log,attestation,eu-ai-act
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: System :: Logging
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Atelya Attest

[![tests](https://github.com/RonaldSit/atelya/actions/workflows/tests.yml/badge.svg)](https://github.com/RonaldSit/atelya/actions/workflows/tests.yml)
[![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)
[![Dependencies: zero](https://img.shields.io/badge/dependencies-zero-brightgreen.svg)](#)
[![PyPI](https://img.shields.io/pypi/v/atelya-attest)](https://pypi.org/project/atelya-attest/)

**Can you prove your AI agent's memory wasn't tampered with?**

Atelya Attest gives agent memory a cryptographic paper trail: every memory
operation is hash-chained, the chain head is checkpointed into an external
witness ledger, and GDPR erasure leaves a verifiable marker instead of a
silent hole. Pure Python stdlib — your auditor can rewrite the verifier in an
afternoon.

**[atelyaos.com](https://atelyaos.com)** — live tamper demo, dated
benchmarks, and the engine side of the project.

```bash
pip install atelya-attest
```

No install is required either: the tools are stdlib-only and run straight from
a clone (`python3 amem_attest.py --help`).

0.2.0 (2026-11-04) adds HMAC erasure markers, hard-purge reach, the
attest-chain guard, strict op-log parsing with `repair`, and post-purge hooks,
and fixes option order on older Pythons; see [CHANGELOG.md](CHANGELOG.md).

## 60-second proof

```bash
printf '{"op":"add","id":"m1","text":"patient allergic to penicillin","created_at":1718000000}\n' > log.jsonl
atelya-govern attest log.jsonl --out chain.jsonl
atelya-govern verify-chain chain.jsonl
# ✅ VERIFIED — intact: 1 entries, root=…

python3 -c "import pathlib as p; f=p.Path('chain.jsonl'); f.write_text(f.read_text().replace('penicillin','aspirin'))"
atelya-govern verify-chain chain.jsonl
# ❌ TAMPER DETECTED at seq=0: curr_hash mismatch  (exit 1 — CI-ready)
```

## What you get

| Capability | Command | The guarantee |
|---|---|---|
| Seal a memory log | `atelya-govern attest` | every event hash-chained; one ROOT commits the whole history |
| Verify integrity | `atelya-govern verify-chain` | a single flipped byte fails **at the exact record**, exit 1 |
| Keyed chains | `--key / --keyfile / $ENV` (HMAC-SHA-256) | wrong key fails; **empty/whitespace keys are refused** — no silent HMAC→SHA-256 downgrade |
| External anchoring | `atelya-anchor anchor / check / latest` | rewrite-and-rechain attacks surface as **ANCHOR CONFLICT**; a forgotten `--label` **fails loudly and lists what exists** instead of silently passing |
| GDPR erasure | `atelya-govern erase [--hard]` | soft = auditable forget (text retained); hard = the record and every event naming it removed from the op-log and its side files, marker records only an **HMAC-SHA-256** of the pattern (key in `<data_dir>/.erasure_key`) — the erasure is recorded, and without the key the pattern cannot be confirmed by hashing guesses; refuses while the default attest chain exists (see *Guarantees*) |
| Audit views | `audit / lineage / conflicts / summary` | full timeline, one record's life, flagged contradictions |
| Retention | `retention --max-age / --max-active` | age/cap-based retirement, logged like everything else |
| Post-purge hooks | entry-point group `atelya.purge_hooks` | after every hard erase/retention, each installed hook gets the purged ids, **SHA-256 digests** of their texts and (erase only) the matcher — never the text — so a product can remove its own copies; the CLI prints every hook's outcome (or that none is installed) and exits 1 if one failed |
| Auditor export | `audit --out report.json` (or `.csv`) | machine-readable evidence for compliance packs |
| Self-tests | `--selftest` on all three tools | known-answer vectors, runnable anywhere, offline |

## How it works

```
 memory op-log (JSONL)        attest              external witness
 add / supersede / forget ──► hash chain ──ROOT──► ledger (append-only,
 erase(soft|hard)             (± HMAC)             monotonic, C2SP-style
        │                        │                 consistency checks)
        └── every event ─────────┘
```

- Each entry stores `prev_hash` + `curr_hash = H(prev ‖ payload)`; the final
  hash is the **ROOT** commitment.
- Anchoring follows the transparency-log discipline (RFC 6962 / C2SP
  tlog-checkpoint spirit): checkpoints must be **monotonic** and **consistent**
  with everything previously anchored — so rewriting history and re-chaining
  passes self-verification but is caught against the ledger.
- Everything is line-oriented JSON on disk. No database, no daemon, no
  network, no dependencies.

**Auditors:** [ATTESTATION.md](ATTESTATION.md) gives the exact hash construction
(precise enough to write your own verifier), a threat model per adversary
capability, the regulatory control mapping, and a copy-paste runbook.

## Use it from Python

```python
from amem_attest import build_chain, verify_chain, root_of

events = [{"op": "add", "id": "m1", "text": "patient allergic to penicillin"}]
chain = build_chain(events, key=None)        # key=b"..." switches to HMAC-SHA256
print(root_of(chain))                        # the commitment you anchor / publish
ok, bad_seq, reason = verify_chain(chain, key=None)
```

Mutate any field of any entry and `verify_chain` returns `(False, <seq>, <why>)`
— sequence gaps, broken links, and payload edits are all distinguished.

## The attack a chain alone cannot catch

An attacker with write access can tamper **and rebuild the whole chain** — the
file then verifies internally. The transparency-log answer: checkpoint the head
into a ledger the writer cannot touch, then check consistency later.

```bash
atelya-attest attest log.jsonl --out chain.jsonl
mkdir -p ~/anchors        # in production: a different account/host/WORM store
atelya-anchor anchor chain.jsonl --ledger ~/anchors/anchors.jsonl --label prod

# attacker rewrites the op-log AND re-attests the whole chain:
python3 -c "import pathlib as p; f=p.Path('log.jsonl'); f.write_text(f.read_text().replace('penicillin','aspirin'))"
atelya-attest attest log.jsonl --out chain.jsonl

atelya-attest verify chain.jsonl                 # ✅ VERIFIED — the chain alone is blind
atelya-anchor check chain.jsonl --ledger ~/anchors/anchors.jsonl --label prod
# ❌ ANCHOR CONFLICT … history rewritten (same-position different-root) — exit 1
```

Run the ledger under **separate control** (different account/host/WORM store);
separation of duties is what turns "detects accidents" into "detects insiders".

## Guarantees — and non-guarantees

- **Tamper-EVIDENT, not tamper-proof.** Anyone claiming tamper-proof is
  overselling. Detection is the guarantee; prevention needs your storage
  controls, and rewrite-resistance needs the external anchor (shipped).
- A forgotten `--label` on `check` is treated as an operator error, not a
  pass: the tool fails and lists the labels the ledger actually holds.
- Hard-erase removes the record from the op-log and its side files but never
  the fact of erasure: a purge marker (an HMAC of the pattern, never the
  text) stays in the op-log. The chain stores every event verbatim, so a hard
  purge refuses while the default chain file (`<oplog>.attest.jsonl`) exists;
  `--drop-attest` deletes it, with the history it recorded. A chain built
  after the purge starts again from GENESIS, so checking it against a root
  anchored before the purge reports ANCHOR CONFLICT, as for any rewrite.
  Chains written elsewhere with `--out` are neither checked nor cleaned. A
  chain that stores only hashes and can be verified across purged positions
  (attest v2) is not implemented.
- Trust boundary: the verifier is ~200 lines of stdlib Python. Don't trust
  this repo — read it, or rewrite it.

## Verify it yourself

From a clone (the 211-test suite lives here, not in the wheel):

```bash
python -m pytest tests/ -q      # 211 tests: known-answer vectors, tz-matrix,
                                # tamper/reorder/truncation, erasure semantics
atelya-attest --selftest && atelya-anchor --selftest && atelya-govern --selftest
# ^ these three work from a pip install too — offline, no network
```

We pre-register benchmark pass lines and **publish the misses**: the most
recent full-system billing run (2026-07-08) missed our own bar by 1.5 points,
after two runs on 2026-06-11 that met it (figures under *About Atelya OS*
below). Those runs are recorded in the engine's changelog, which is not
published here; this repo's CHANGELOG covers the attest layer only.

## Where this fits

Atelya Attest is a **bolt-on evidence layer, not a memory store** — there is
nothing to migrate. If your memory system can emit one JSON event per line
(add / supersede / forget / erase), you get:

- a hash chain over that lifecycle, committed by a single ROOT
- pinpoint verification — `TAMPER DETECTED at seq=N`, exit 1, CI-ready
- external anchoring that catches whole-history rewrites
- GDPR soft-forget / hard-purge with HMAC-SHA-256 markers
- auditor exports (JSON / CSV) and three offline `--selftest`s

Deliberately no performance comparisons: run your own eval, on your own data.

## Why now

The EU AI Act's logging/record-keeping duty (Art. 12) for high-risk AI
systems is coming with runway: the Digital Omnibus moved standalone
high-risk (Annex III) duties to **2 December 2027**, while GDPR erasure is
enforceable **today** (dates verified 2026-07). This layer produces the
evidence trail those audits ask for; sources and control mapping
(EU AI Act / SOC 2 / NIST SP 800-92) live in [ATTESTATION.md](ATTESTATION.md).

## FAQ

**Is this "tamper-proof"?** No — tamper-evident, plus external anchoring
against rewrite-and-rechain. See *Guarantees* above.

**We already have a memory stack.** Keep it. If it can emit
JSONL events, the attest layer bolts on today — three commands, zero
dependencies, nothing replaced.

**You don't have SOC 2 — why would our auditor care?** Because they never
have to trust us: the verifier is stdlib, offline, and rewritable in an
afternoon, and our benchmark misses are published. Certifications are
roadmap; verifiability ships now.

## About Atelya OS

Atelya Attest is the open, self-verifiable layer of a larger system. The
engine — semantic memory with same-key supersede, drop-in
closed-API orchestration and KV-native serving — is
not published here. Measured on our own bills, not extrapolated, in the
engine's full-system billing harness (one 24-turn session per run): memory
tokens **−76.8%** at turn 12 (**2026-07-08**); final turn **−88.0%** and
**−87.1%** (two runs, **2026-06-11**) and **−84.5%** (**2026-07-08** rerun);
full-system saving *including* the extraction tax **+39.1%** and **+37.7%**
(2026-06-11, inside our own pre-registered line) and **+33.5%** (2026-07-08,
which **missed that line by 1.5 points — published as measured**).
Self-hosted KV reuse (CacheBlend, LongMemEval-S, n=200 per run,
Qwen2.5-7B-AWQ on one RTX 4070, in-process reference): **6.12× cheaper
prefill** in both runs, at **97.5%** per-query agreement with a cold full
prefill (**2026-06**: 195/200 same verdict from an independent LLM judge,
claude-haiku-4-5 at temperature 0) and **96.5%** (**2026-07-11** rerun:
193/200 under lexical-match scoring, no LLM judge). Both measured with the
engine's `bench_real.py` (not published here). The speedup cannot be
demonstrated on WSL2.

We're onboarding **3 design partners**: regulated teams who want the memory
layer *and* the evidence layer, with our hostile acceptance suites run on
their machines. → `ronald@atelyaos.com`

## Roadmap

- [x] PyPI package (`pip install atelya-attest`) — release **0.2.0** (2026-11-04)
- [x] External anchor ledger with monotonic/consistency checks
- [x] Erasure markers that never hold the literal pattern (HMAC-SHA-256 with a per-data-directory key since 0.2.0; plain SHA-256 in 0.1.x)
- [ ] Optional Ed25519 / ML-DSA signing (stdlib HMAC stays the default)
- [x] Live-store invalidation after hard-erase: post-purge hooks
  (`atelya.purge_hooks`, since 0.2.0); engine 0.3.0 uses them to
  clean its session and memory-tool files, and its running servers reload the
  store when the purge epoch file changes. GPU KV caches built from erased
  text are not covered.

## How this was built

**AI-assisted, human-verified.** Much of this code was written with AI assistance.
Every claim in this README was executed and checked against real output before
publication — that is what the 211-test suite, the four adversarial acceptance
suites, and the published benchmark misses in [CHANGELOG.md](CHANGELOG.md) are
for. Where a run failed, the failure is in the history rather than edited out.

## Security & license

Vulnerabilities: see [SECURITY.md](SECURITY.md) (private reporting).
Apache-2.0 — see [LICENSE](LICENSE).
