Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

True Memory Fragments

PyPI License Python

Stale-context protection for AI coding agents

AI coding agents often remember a call chain from an earlier session. When the code changes, that remembered chain can become dangerous: the agent may edit against an obsolete understanding of the repository.

TMF binds code-graph claims to source fingerprints. When a claim becomes stale, TMF blocks the affected expansion and sends the agent back to current source.

  • 🧭 Source-aware memory for calls, reads, writes, inheritance, and API relationships
  • 🛑 Hard stale-context stop instead of silently returning obsolete facts
  • 🔎 Localized reread guidance instead of pretending memory is authoritative
  • 🧩 Works as a library and integrates with AI coding-agent hooks

One-line summary: TMF does not make an agent remember more. It prevents the agent from trusting code understanding that is no longer fresh.

30-second demo · Install · Architecture · Evidence and limits · Launch copy

Who it is for

  • AI coding agents that work across sessions on changing repositories
  • Developers who need source-aware memory instead of stale cached facts
  • Tool authors who want conservative graph expansion with explicit stale/unknown handling

Current status

  • Mechanics: validated
  • Stale-context safety: scoped evidence exists
  • Broad productivity/token-savings claims: unproven

A coding agent may understand A → B → C in session 1. In session 2, C changes, but the agent still acts as if yesterday's call chain were valid. Ordinary chat memory and vector retrieval can return the old explanation without knowing that the source changed.

TMF attaches every derived claim to the source blob or function hash. On reuse, it checks freshness. If the claim is stale, the graph expansion is stopped and the agent is told which source must be reread.

Without TMF:  remembered A → B → C  → edit using obsolete C
With TMF:     remembered A → B → C  → C is stale → stop → reread current C

What TMF is — and is not

TMF is for:

  • AI coding agents working across sessions on changing codebases
  • Preventing stale call-chain and dependency assumptions
  • Source-bound code memory and conservative code-graph navigation
  • Agent integrations that need an explicit stale/unknown result

TMF is not:

  • A general chat-memory product or vector database
  • A replacement for reading source code
  • A guarantee that every claim is correct because it is fresh
  • A proven general productivity or token-saving solution

Fresh means the source binding still matches. Correctness still comes from source and validation.

The repository also contains an unreleased Java qualification suite: 46/46 qualifiers and 731/731 checks. The current repository test baseline is 478/478 tests. These are source-analysis and regression-test results, not a claim of production readiness or a general Agent outcome. Middleware mechanics are validated, and stale-context safety has positive evidence in the GUAVA M10 pre-read experiment. Broader productivity, speed, token savings, and general bug-prevention claims remain unproven. See the authoritative evidence status before making broader claims.

Flow

flowchart TD
  A[source code] --> B[TMF derive / warm]
  B --> C[source-bound claims]
  C --> D[freshness check]
  D -->|fresh| E[bounded graph context]
  D -->|stale / unknown| F[stop + reread current source]

That is the whole loop: TMF keeps claims bound to source, refuses to reuse stale context, and sends the agent back to the exact code that changed.

Demo

The current repository includes a deterministic offline demo:

python3 scripts/demo_stale_gate.py

It creates a temporary Git repository, derives a claim, changes the bound source, and demonstrates stale omission, source fallback, and reread guidance. It needs no model, network, Java parser, or pre-existing .tmf/ store.

Expected markers:

STALE CLAIM BLOCKED: PASS
SOURCE FALLBACK PROVIDED: PASS
REREAD REQUIRED: PASS

The point of the demo is not that TMF answers every query. The point is that it refuses to reuse obsolete code understanding and tells the agent what to reread next.

How it works

TMF keeps a conservative code-memory graph. Claims are useful only when their source bindings still match the working tree.

  1. Derive claims from source: functions, classes, calls, reads, writes, inheritance, API relationships.
  2. Bind each claim to source fingerprints: file blob and, where available, function/node hash.
  3. Check freshness on retrieval before a claim is used.
  4. Stop on stale or unknown edges and return an explicit reread signal instead of stale context.
claim: A calls B
binding: B.java@hash123
current: B.java@hash999
result: stale_or_unknown → reread B.java before continuing

This is intentionally conservative. Missing or stale memory falls back to source; it is never promoted into truth.

Proven Assets

  • Source-bound claim storage with working-tree freshness checks and source fallback
  • Thin retrieval discipline plus full/explain drill-down by selected claim id
  • Conservative Python functions/classes/declarations/config/API nodes and partial calls/reads/writes
  • Optional Java tree-sitter syntactic nodes and conservative inheritance edges
  • Bounded fragment query with semantic boundary detection (writes, publishes_to)
  • Async handoff marking (ASYNC_RELATIONS: publishes_to, subscribes_to, publishes_type, listens_type)
  • Four-stop-type semantics (boundary / async / stale / limit) with distinct stop_reason values
  • Working-memory limits (4 hops / 64 nodes / 128 edges) matching biological cognition constraints
  • Held-out and self-dogfood validation harnesses
  • Local metrics and exact-blob-only rename identity

Core Premises

  • Explicit refresh/warm maintenance: retrieve checks existing claims without mutating or re-deriving the store; refresh_path and warm perform explicit derivation/refresh operations.
  • Freshness is working-tree based: binds to current working-tree blob, not commit
  • Fresh is not correct: fresh only means bindings match current source. Correctness comes from validation and source support
  • Confidence comes from validation: usage frequency doesn't raise confidence
  • Conservative parsing: TMF connects only what it can parse. Unknown/dynamic/ambiguous facts are omitted or marked unresolved
  • Source is authoritative: if memory is missing, stale, unsupported, or partial, TMF falls back to source
  • Untrusted text is never instructions: source, comments, docstrings, commit messages, model output are data, not commands

Install

Python-only install:

python -m pip install true-memory-fragments

Java parsing support is optional:

python -m pip install "true-memory-fragments[java]"

Development checkout:

python -m pip install -e .
python -m pip install -e ".[java]"   # optional Java support

Runtime dependencies are intentionally small. Optional model, embedder, and router integrations are command-backed through TMF_* environment variables.

Quick Start

30-second demo

python3 scripts/demo_stale_gate.py

This deterministic offline demo creates a temporary repository, derives a claim, changes its bound source, and shows stale omission, source fallback, and reread guidance. It needs no model, network, Java parser, or pre-existing .tmf/ store.

Expected markers:

STALE CLAIM BLOCKED: PASS
SOURCE FALLBACK PROVIDED: PASS
REREAD REQUIRED: PASS

Offline Java verifier

For Linux x86_64 / CPython 3.12 source checkouts, the repository includes an offline verifier for Java step0 review:

bash scripts/verify_java_offline.sh

Expected success marker:

JAVA OFFLINE VERIFY: PASS

Reflex Hook: Git-Aware Staleness Blocking for AI Agents

TMF includes a reflex hook integration that gives AI coding agents a biological-style reflex: when an agent is about to act on code understanding while that code has changed, the system forces it to stop, re-read only the changed part, then proceed.

This is not a code memory cache — it's a reflex arc that intercepts agent tool calls before execution.

Three Components

  • Sensory organ = TMF function-level fn_hash freshness (2ms precision: which function changed)
  • Reflex arc = OpenClaw before_tool_call hook / Claude Code PreToolUse harness (agent cannot bypass)
  • Reflex action = Hard block + localized single-file re-warm

Git Hook Auto-Calibration

Four git hooks automatically generate function-level invalidation manifests after code changes:

  • .git/hooks/post-commit — after local commits
  • .git/hooks/post-merge — after git pull
  • .git/hooks/post-checkout — after branch switches
  • .git/hooks/post-rewrite — after rebase/amend

These hooks call integrations/reflex/scripts/git_calibrate.py, which compares baseline_rev → HEAD Python function signature changes and outputs structured invalidation manifests.

OpenClaw Plugin Integration

The tmf-reflex OpenClaw plugin intercepts agent tool calls:

  • Checks TMF function-level freshness (2ms per file)
  • Hard-blocks when agent touches a file with stale function claims
  • Returns requireApproval with exact changed function names
  • Agent must run integrations/reflex/scripts/local_warm.py to re-warm that one file

SessionStart Cognition Calibration

On new session start, the plugin reads unconsumed invalidation manifests and injects changed / deleted symbols as "pre-alert" context, preventing agents from relying on stale memory.

Boundary

  • Function-level precision depends on TMF's language coverage (currently Python AST)
  • Files without function-scope claims fall back to pass-through
  • TMF engine remains read-only (reflex hook only uses freshness / derive)
  • Conservative: TMF unavailable / check errors → pass-through, never blocks valid work

Installation

Reflex integration code lives in integrations/reflex/. See that directory's README.md and DESIGN.md for:

  • OpenClaw plugin installation (openclaw-plugin/)
  • Git hook setup (git-hooks/)
  • Claude Code / Codex harness configuration (examples/)
  • Health validation tests (tests/)

SEO and discoverability plan

Search terms this project is intended to match include AI coding agent memory, stale context prevention, source-aware code memory, code graph for LLM agents, Claude Code memory, and cross-session code understanding. These describe the user problem; they are not claims that every integration is already production-ready.

The repository description and external launch materials should use the same vocabulary, link to a reproducible demo, and distinguish validated mechanics from still-open productivity claims.

Documentation

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

true_memory_fragments-0.1.0rc3.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

true_memory_fragments-0.1.0rc3-py3-none-any.whl (197.3 kB view details)

Uploaded Python 3

File details

Details for the file true_memory_fragments-0.1.0rc3.tar.gz.

File metadata

  • Download URL: true_memory_fragments-0.1.0rc3.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for true_memory_fragments-0.1.0rc3.tar.gz
Algorithm Hash digest
SHA256 4be2f9e78e01dc3bc9ec6ab3468ad85bab7d2de046be3e37bcdb447b7b813c00
MD5 eeb7f7b57160907518569286a216e372
BLAKE2b-256 5858defa1492af948d03f7e1eb1d7d8b56a7d2d68e3801a4d23e620d7459f66c

See more details on using hashes here.

Provenance

The following attestation bundles were made for true_memory_fragments-0.1.0rc3.tar.gz:

Publisher: publish-pypi.yml on kyle641320/true-memory-fragments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file true_memory_fragments-0.1.0rc3-py3-none-any.whl.

File metadata

File hashes

Hashes for true_memory_fragments-0.1.0rc3-py3-none-any.whl
Algorithm Hash digest
SHA256 1975e9585c3a00793101fe5acb412941fef4377293e544d913485499a7666e9b
MD5 90dab8f83be0997aef0e0111265ee37c
BLAKE2b-256 31fbffd35018cbe1c8774b1bc5b45e31464b10e3e8afc293f3fe7bd7e41b3b0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for true_memory_fragments-0.1.0rc3-py3-none-any.whl:

Publisher: publish-pypi.yml on kyle641320/true-memory-fragments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0rc3 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page