From d95242fe351b167f82a68aeaf2106d50b2f82c66 Mon Sep 17 00:00:00 2001 From: Edbert Chan Date: Wed, 16 Sep 2026 14:15:27 -0700 Subject: [PATCH] Search saved memory both ways before a deep dive An answer already written down costs one read. Add the learned rule and a test that pins it. Co-Authored-By: Claude Opus 5 (1M context) Change-Id: I8831f9085cdb5fe672f820dbe96186ca5dc74b29 --- corpus/CLAUDE.learned.md | 1 + tests/test_check_memory_first_rule.py | 39 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/test_check_memory_first_rule.py diff --git a/corpus/CLAUDE.learned.md b/corpus/CLAUDE.learned.md index a0915658..3ba236dd 100644 --- a/corpus/CLAUDE.learned.md +++ b/corpus/CLAUDE.learned.md @@ -45,3 +45,4 @@ Engine-only install drops this file; reflect Accepted global rules land here. - Before asking me whether to run a script, read its whole body, not its header comment, usage text, or `--dry-run` output, and name in the question every process it kills, file it deletes, and service it restarts. A header states what the author meant; the body is what runs, so a consent question built from the header asks me to approve something other than what will happen. No known prior art. - When finishing a merge or rebase, reconcile three things before calling it resolved: what each side declared (its commit messages and PR description: the intent, and the tests it names), what each side's code actually does, and what the resolved result does. All three must agree: every declared intent is still visible in `git diff -- `, and every test either side named still passes on the result. A merge with no textual conflict can still break one side's declared behavior, so a clean merge is checked the same way. Never take one side's whole file (`git checkout --theirs` / `--ours `, or copying the file from one branch) unless the other side's changes to that file are provably empty; taking a whole side silently reverts what the other branch added, including hunks that never conflicted (git-checkout(1), `--ours`/`--theirs`: https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt---ours). When a declaration and its code disagree, or the two sides' intents contradict, stop and flag it to me instead of choosing: run `why` on the conflicting lines (`git log -L` or `git log -S` plus each commit's PR body) and apply `principle-prove-it`, so the flag names the two commits or PRs, quotes the declared intent next to the code, and pastes the failing test output. Brun, Holmes, Ernst and Notkin, "Proactive Detection of Collaboration Conflicts" (ESEC/FSE 2011, https://doi.org/10.1145/2025113.2025139), across Git, Perl5 and Voldemort, found "that 33% of merges that were reported to contain no textual conflicts by the VCS in fact contained higher-order conflicts" (build or test failures), so a clean textual merge is not evidence the two intentions still hold. - An item I approved as "fix it properly later" stays in every status update and every final summary, marked open, until it is done or I drop it. A recap that lists only what finished makes the deferred half disappear, and the next session never learns it was owed. No known prior art. +- Before spending more than a couple of tool calls on an infrastructure, security, or "does X exist" question, search saved memory for the topic and for its reverse framing: the fix as well as the symptom, "X is off" as well as "X is missing". An answer already written down costs one read; rediscovering it costs the whole investigation. No known prior art. diff --git a/tests/test_check_memory_first_rule.py b/tests/test_check_memory_first_rule.py new file mode 100644 index 00000000..15712b92 --- /dev/null +++ b/tests/test_check_memory_first_rule.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +"""Pin the learned rule: search saved memory, both ways, before a deep dive. + +A detector cannot judge this reliably, so the test proves the rule is present +with its trigger, required action, and reason; deleting or hollowing it fails here. +""" +import os +import unittest + +REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +LEARNED = os.path.join(REPO_ROOT, "corpus", "CLAUDE.learned.md") + + +def working_style_section(): + with open(LEARNED, encoding="utf-8") as handle: + text = handle.read() + start = text.index("# Working style") + end = text.find("\n# ", start + 1) + return text[start:] if end == -1 else text[start:end] + + +def bullet_starting(prefix): + for line in working_style_section().splitlines(): + if line.startswith(prefix): + return line + raise AssertionError(f"no working-style rule starts with {prefix!r}") + + +class TestCheckMemoryFirst(unittest.TestCase): + PREFIX = "- Before spending more than a couple of tool calls" + + def test_rule_searches_memory_both_ways(self): + rule = bullet_starting(self.PREFIX) + self.assertIn("search saved memory", rule) + self.assertIn("reverse framing", rule) + + +if __name__ == "__main__": + unittest.main()