From d6e5fa7176efbf4a48f103778ce45a54313371da Mon Sep 17 00:00:00 2001 From: Matias Date: Tue, 4 Aug 2026 02:35:53 -0300 Subject: [PATCH 1/2] docs: the published scoring formula stopped being the one the code uses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `README.md` and `ARCHITECTURE.md` both showed score = (frequency × 0.4) + (recency × 0.4) + (context × 0.2) which survived two releases past the point of being true: through the fix that normalised frequency (that formula's central defect) and through the feature that added prefix and picks. Anyone reading it to understand why a result ranked where it did was reading a description of code that no longer exists. Also corrected: `vars.json` is described as the variable store, when it now only records which variables exist and the values are in the Keychain; and ARCHITECTURE's decision index stopped at ADR-004 while eleven exist. Nothing detects prose going stale, so the parts that can be mechanical now are: - every ADR must be linked from the decision index; - no link to `docs/decisions/` may be broken; - the published formula must name every `W_*` weight in `mem.ranking`, derived from the module rather than a hard-coded list, so a sixth feature fails this test until it is written down. The last one needed a second attempt. Bounding the check to a fixed 400-character window reached past the formula into the bullet list beneath it, so deleting a term from the formula still passed — the term was named in the surrounding prose. It is now bounded at the first blank line, and verified by deleting a term and watching it fail. --- ARCHITECTURE.md | 25 ++++++++++++---- README.md | 20 ++++++++++--- tests/test_e2e.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 10 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 2ae5f4f..3b48bdf 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -122,15 +122,21 @@ search.search("kubectl", current_repo="infra") ├── read other repo files │ ▼ -Filter: substring match "kubectl" in command text +Prefilter: needle test on the raw line's command span (skips json.loads) │ ▼ -Score each match: - score = (frequency × 0.4) + (recency × 0.4) + (context × 0.2) +Filter: every query term must appear in the command text + │ (if nothing matches, expand through the concept map and retry) + ▼ +Score each match (mem/ranking.py — stdlib only, shared with the finder): + score = (picks × 0.40) + (frequency × 0.21) + (recency × 0.21) + + (prefix × 0.09) + (context × 0.09) │ - ├── frequency: count of identical commands - ├── recency: exp(-days × ln2/7), half-life 7 days - └── context: 1.0 same repo, 0.5 same prefix, 0.0 other + ├── picks: 1 - 2^-w over the finder's decayed selections, 21d half-life + ├── frequency: log1p(n)/log1p(50), capped at 1 + ├── recency: exp(-days × ln2/7), half-life 7 days + ├── prefix: 1.0 if the command starts with the query + └── context: 1.0 same repo, 0.5 sibling, 0.0 other │ ▼ Deduplicate by command string (keep highest score) @@ -423,3 +429,10 @@ See `docs/decisions/` for detailed ADRs: - [002: Apple FM SDK for Patterns](docs/decisions/002-apple-fm-sdk-for-patterns.md) - [003: No Daemon, Background Subprocess Instead](docs/decisions/003-no-daemon.md) - [004: Per-Repository JSONL Files](docs/decisions/004-per-repo-jsonl.md) +- [005: A Derived Index, With the JSONL as the Source of Truth](docs/decisions/005-derived-index-jsonl-source-of-truth.md) +- [006: App Intents, Shortcuts and Spotlight — Evaluated and Deferred](docs/decisions/006-app-intents-shortcuts-spotlight-deferred.md) +- [007: MCP Over Stdio, Never HTTP](docs/decisions/007-mcp-over-stdio-never-http.md) +- [008: The Interactive TUI Is Built on the Standard Library](docs/decisions/008-stdlib-tui.md) +- [009: Ranking Learns From What You Select](docs/decisions/009-ranking-learns-from-selections.md) +- [010: The Keychain for Variable Values](docs/decisions/010-keychain-for-variable-values.md) +- [011: A Concept Map, Not Embeddings](docs/decisions/011-concept-map-over-embeddings.md) diff --git a/README.md b/README.md index dc5d534..c721fd0 100644 --- a/README.md +++ b/README.md @@ -559,12 +559,24 @@ You type a command **Search scoring:** ``` -score = (frequency × 0.4) + (recency × 0.4) + (context × 0.2) +score = (picks × 0.40) + (frequency × 0.21) + (recency × 0.21) + + (prefix × 0.09) + (context × 0.09) ``` -- **Frequency** — how often you've run this command +- **Picks** — how often you chose this command in the finder, halving every + 21 days. Weighted highest because it is the only signal that is not an + inference: it is you having already answered the question. Zero until you + use `Ctrl+R`, and with none recorded the ordering is exactly what the other + four produce on their own. +- **Frequency** — how often you ran it: `log1p(n)/log1p(50)`, capped, so the + jump from 1 to 5 counts and one repeated command cannot own every result - **Recency** — exponential decay, 7-day half-life -- **Context** — 1.0 same repo, 0.5 same directory prefix, 0.0 otherwise +- **Prefix** — the command *starts with* your query, not merely contains it +- **Context** — 1.0 same repo, 0.5 sibling directory, 0.0 otherwise + +Every feature is normalised to [0, 1] and the weights sum to 1, so a score +reads as a fraction. If nothing matches literally, the +[concept map](#search) expands the query — and only then. **AI features** use [Apple Foundation Models](https://developer.apple.com/machine-learning/api/) running entirely on your Mac's neural engine. No API keys, no cloud, no data leaves the machine. If Apple Intelligence isn't available, everything still works — you just don't get pattern extraction or credential detection. @@ -591,7 +603,7 @@ beside them, is rebuilt from them, and is safe to delete: myapp.json # repo-scoped groups and saved commands _global.json # global groups and saved commands concepts.json # your concept map, layered over the shipped one - vars.json # persistent variable store (0600 permissions) + vars.json # which variables exist (values are in the Keychain) agent.json # AI agent access flag (off unless you enabled it) agent-audit.jsonl # append-only record of every agent request ``` diff --git a/tests/test_e2e.py b/tests/test_e2e.py index 6e741dd..2aed66e 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -600,3 +600,79 @@ def test_version_returns_quickly(self, home: Path, workdir: Path) -> None: assert "mem" in result.stdout assert min(durations) < 0.5, f"mem --version took {min(durations):.3f}s" + + +class TestDocumentationDoesNotDrift: + """Docs that state a formula the code no longer uses are worse than none. + + Both `README.md` and `ARCHITECTURE.md` published + `score = frequency*0.4 + recency*0.4 + context*0.2` for two releases after + that formula stopped existing — through the fix that normalised it and the + feature that added two more terms. Nothing detects prose going stale, so + the checks that can be mechanical are made mechanical. + """ + + DOCS = ["README.md", "ARCHITECTURE.md", "PHILOSOPHY.md", "CHANGELOG.md"] + + def test_every_adr_is_listed(self) -> None: + """A decision nobody can find from the index may as well not exist.""" + index = (REPO_ROOT / "ARCHITECTURE.md").read_text(encoding="utf-8") + missing = [ + path.name + for path in sorted((REPO_ROOT / "docs" / "decisions").glob("*.md")) + if path.name not in index + ] + + assert not missing, f"ADRs not linked from ARCHITECTURE.md: {missing}" + + def test_no_link_to_a_decision_record_is_broken(self) -> None: + import re + + broken: list[tuple[str, str]] = [] + for name in self.DOCS: + text = (REPO_ROOT / name).read_text(encoding="utf-8") + for match in re.finditer(r"\]\((docs/decisions/[^)]+)\)", text): + if not (REPO_ROOT / match.group(1)).exists(): + broken.append((name, match.group(1))) + + assert not broken, f"broken ADR links: {broken}" + + def test_the_published_scoring_formula_names_every_feature(self) -> None: + """The docs must not describe a ranking that stopped existing. + + Checked against `mem.ranking`'s own weight constants rather than a + hard-coded list, so adding a sixth feature fails here until it is + written down. + """ + from mem import ranking + + features = [ + name[2:].lower() + for name in dir(ranking) + if name.startswith("W_") and isinstance(getattr(ranking, name), float) + ] + assert features, "no weight constants found — did they get renamed?" + + for name in ("README.md", "ARCHITECTURE.md"): + formula = self._formula_in(REPO_ROOT / name) + unmentioned = [f for f in features if f not in formula] + assert not unmentioned, ( + f"{name} publishes a formula missing {unmentioned}; " + f"it is describing a ranking the code does not use:\n{formula}" + ) + + @staticmethod + def _formula_in(path: Path) -> str: + """The formula itself, not the prose around it. + + Bounded at the first blank line after `score =`. An earlier version + took a fixed 400-character window, which reached far enough to include + the bullet list underneath — so the check passed against a formula + with a term deleted, because the term was still named in the prose. + Verified by deleting one. + """ + text = path.read_text(encoding="utf-8").lower() + start = text.find("score =") + assert start != -1, f"{path.name} no longer shows the scoring formula" + end = text.find("\n\n", start) + return text[start : end if end != -1 else len(text)] From 472614f33721a41a0b75ebc1db70aed7f3955e96 Mon Sep 17 00:00:00 2001 From: Matias Date: Tue, 4 Aug 2026 02:36:59 -0300 Subject: [PATCH 2/2] docs: reconcile the plain-text claim with the Keychain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The privacy list promises plain-text storage; variable values are now deliberately not plain text. Both are true and the exception is the point — "readable with cat" is the wrong property for a password — but a reader hitting the two claims in sequence has no way to know that without being told. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c721fd0..e1e70d2 100644 --- a/README.md +++ b/README.md @@ -639,7 +639,10 @@ Data rotation happens automatically in the background: - Zero telemetry — no analytics, no crash reports - Zero cloud dependencies — fully offline, always - On-device AI only — runs on your Mac's neural engine -- Plain text storage — no proprietary formats, you own your data +- Plain text storage — no proprietary formats, you own your data. The one + deliberate exception is variable *values*, which live in the macOS + Keychain: "readable with `cat`" is the wrong property for a password + ([ADR-010](docs/decisions/010-keychain-for-variable-values.md)) - Agent access off by default — opt-in, redacted and audited ([MCP](#ai-agents-mcp)) Read more in [PHILOSOPHY.md](PHILOSOPHY.md).