Files
alirezarezvani__claude-skills/engineering/memory-engineering
Claude 2c384a9c47 fix(memory-engineering): close an F1 bypass and make --print-sample-spec reachable
Fourth review on PR #947 reported two functional bugs, explicitly noting it had
not run anything. Both reproduced, and the first is severe.

1. F1 -- the blocking gate -- could be bypassed by a typo.

   _check_forgetting_rule() failed only when `rule` was literally
   "none"/""/"never", and otherwise inferred PASS from what the rule was *not*.
   So anything unrecognized fell through to the PASS branch with an empty
   mechanism list. Reproduced:

     {"rule": "asdf"}             -> F1=PASS  "Forgetting is designed: ."
     {"rule": "ttl"} (no ttl_days)-> F1=PASS  "Forgetting is designed: ."

   A misspelling silently passed the one check this entire skill is built
   around, and the nonsensical detail string was the only hint.

   The check is now allowlist-based: PASS is unreachable unless a concrete
   mechanism is actually found (ttl_days > 0, max_records/max_bytes > 0, or a
   decay setting). Failure messages now distinguish an unrecognized rule from a
   declared-but-unconfigured one, so a typo is never mistaken for a deliberate
   decision not to forget. Booleans are rejected where a number is expected,
   and ttl_days=0 counts as absent.

   Verified across 10 cases: all six bypass variants now FAIL at exit 4, all
   four legitimate mechanisms still PASS, and the empty-mechanism string can no
   longer be emitted.

2. --print-sample-spec was unreachable on all three scripts that offer it.

   The flag sat outside a mutually-exclusive group declared required=True, and
   argparse enforces that during parse_args() -- before any of our code runs.
   So the flag alone exited 2 with a usage error, which broke the first line of
   the workflow SKILL.md documents verbatim:

     python scripts/memory_cost_profiler.py --print-sample-spec > workload.json

   The group is now required=False with explicit post-parse validation, so
   no-args still errors helpfully and names all valid entry points. Verified the
   full round-trip on all three: --print-sample-spec > f.json, then feed f.json
   back in.

   This slipped through because the PR's own checklist covered --help, --sample
   and --output json, but never ran --print-sample-spec standalone.

Also removed the identity dict in render() flagged as a nit.

Verified: 4/4 scripts help/sample/json; error paths 3/4/4; all six blocking
gates; checklist 6/6 PASS; security auditor PASS (0 critical, 0 high, 0 info).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jt1sqt5kQmopyfXu2Hhjnv
2026-08-09 05:10:36 +00:00
..

memory-engineering

Your agent's problem was never that it forgets. It's that it never forgets on purpose.

A storer optimizes what a system remembers. A memory engineer optimizes what it forgets. This plugin makes that shift executable: four deterministic stdlib scripts that price the write path, choose which cost to pay, audit what a store actually holds, and refuse a design with no forgetting policy.

Why this exists

Everyone building agent memory optimizes retrieval. Almost nobody engineers what it costs to build, what is worth keeping, who can delete it, and where it lands on the hardware. Stanford's systems characterization of ten memory systems found the gap concretely:

  • Construction energy exceeds total query-phase energy across 300 queries — the bill is paid on the write path you never watch.
  • Energy per correct answer spreads more than 47× across systems (BM25 at 4,145 J; MIRIX at ~197 kJ).
  • At 1M tokens, footprint varies up to 9× — and "none of the evaluated systems prune or forget by default."

If you did not build forgetting, you do not have it.

Install

/plugin marketplace add alirezarezvani/claude-skills
/plugin install memory-engineering

Use

/cs:memory-engineering ~/.claude/memory      # full four-lens pass
/cs:forgetting-audit design.json             # just the blocking gate

Or run the scripts directly — each has --help, --sample, and --output json:

cd skills/memory-engineering

python scripts/memory_cost_profiler.py --sample
python scripts/memory_architecture_picker.py --sample
python scripts/memory_density_auditor.py --dir ~/.claude/memory
python scripts/forgetting_policy_linter.py --sample-failing

The four scripts

Script Lens What it does Exit codes
memory_cost_profiler.py Stanford — what does it cost? Splits construction vs query spend, computes cost per correct answer, flags under-amortized writes and construction co-located with live queries 0 · 2 finding · 3 bad input
memory_architecture_picker.py Stanford — which cost to pay? Scores long-context / flat RAG / structure-augmented RAG / agentic against constraints, disqualifies on hard limits, names the cost you're choosing, refuses to pick on a tie 0 · 2 ambiguous · 3 bad input · 4 none viable
memory_density_auditor.py Microsoft — what's worth keeping? Classifies records FACT / SKILL / LOG / PROSE, finds near-duplicates, flags stale and time-relative wording, scores knowledge density. Runs on a real directory or JSONL 0 dense · 2 finding · 3 bad input
forgetting_policy_linter.py Anthropic + the gate 8 checks; F1 (explicit forgetting rule) and F4 (contradictions surfaced, never auto-merged) are blocking 0 PASS · 2 CONDITIONAL · 4 FAIL

Stdlib only. No network, no LLM calls, no dependencies.

The gate

$ python scripts/forgetting_policy_linter.py --sample-failing

VERDICT: FAIL  (0/8 checks pass)
This design does not forget on purpose. F1 failed. F4 failed.

  FAIL  F1  explicit forgetting rule [BLOCKING]
        No TTL, no capacity bound, no decay. The store only grows.
  FAIL  F4  contradictions surfaced, never auto-merged [BLOCKING]
        Contradiction policy is 'newest_wins', which resolves conflicts silently.

F4 is blocking on purpose. Two memories that disagree may both have been true in different contexts — "deploys go through Jenkins" and "deploys go through GitHub Actions" is not a contradiction to resolve, it is a migration to record. Auto-merging destroys the only evidence the conflict existed.

Evidence discipline

The four-lens framing synthesizes "How to be a Memory Engineer, from the perspective of Stanford, Microsoft, Anthropic and Nvidia" by @N01ennn.

Every quantitative claim is cited to the primary source, not to that article, and each carries an explicit confidence level. Two of the article's paraphrases are corrected in the references:

  • The 47× energy figure is the spread across ten evaluated systems, not "two systems with identical accuracy" (memory_cost_canon.md §2).
  • The 97% first-pass-error reduction is Rakuten's named, vendor-published customer testimonial — not a controlled study or a general property of building memory this way (memory_control_and_governance.md §4).

Not this plugin

You want Use
Build and maintain one markdown knowledge vault llm-wiki
A nightly self-improvement loop over transcripts skillopt-sleep
Bound an agent's task loop agent-harness
Price inference generally llm-cost-optimizer

This bounds a store, not a loop and not a vault.

Primary sources

Full citation lists (7 sources each) are in skills/memory-engineering/references/.

License

MIT.